You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用PJSIP发起呼叫时出现SIP注册408请求超时问题求助

Troubleshooting PJSIP 408 Request Timeout After Freeing Port 5060

Let's walk through practical steps to diagnose and fix this registration timeout issue you're facing. The 408 error means your PJSIP client isn't receiving a response from the SIP server within the expected window, and there are several common culprits to check—especially after you had to free up port 5060.

1. Verify Port 5060 is Truly Available

First, double-check that your initial port cleanup actually worked. The command you used (sudo kill 'sudo lsof -t -i:5060') uses single quotes, which prevents the shell from executing the inner lsof command—so it might not have terminated the conflicting process at all!

Run these commands to confirm the port status:

  • Check for processes using 5060: sudo lsof -i:5060
  • Alternative check: netstat -tulpn | grep 5060

If you still see a process listed, use this corrected kill command to terminate it:
sudo kill $(sudo lsof -t -i:5060)

Once done, recheck to ensure the port is clear before running your PJSIP code again.

2. Test SIP Server Reachability

A 408 timeout often stems from the client being unable to reach the SIP server. Let's rule out network issues:

  • Ping the SIP server's IP address: ping <sip-server-ip> to confirm basic connectivity.
  • Test if the server's 5060 port is open and accepting connections: nc -zv <sip-server-ip> 5060 (install netcat if you don't have it). If this fails, the problem is likely with the server itself, your network firewall, or routing between your machine and the server.

3. Validate Your PJSIP Registration Configuration

Double-check that your code's SIP settings haven't been accidentally modified:

  • Confirm the SIP server address, port, username, and password are all correct (match what worked before).
  • Check if your code sets a registration timeout value that's too short. You can try increasing the reg_timeout parameter in your PJSIP endpoint config to give the server more time to respond. For example:
    import pjsua2 as pj
    
    ep = pj.Endpoint()
    ep.libCreate()
    epConfig = pj.EpConfig()
    # Increase registration timeout to 30 seconds (default might be shorter)
    epConfig.uaConfig.regTimeout = 30
    ep.libInit(epConfig)
    

4. Check Local Firewall and Security Rules

Freeing up the port might have coincided with a change in your firewall settings, or the previous process was blocking traffic in a way that's now affecting PJSIP:

  • Check if ufw (Ubuntu/Debian) or firewalld (RHEL/CentOS) is blocking incoming/outgoing traffic on port 5060. For ufw, run sudo ufw status to see active rules—add an allow rule if needed: sudo ufw allow 5060/udp (SIP typically uses UDP).
  • If you're using SELinux, verify it isn't restricting PJSIP's network access. You can temporarily set it to permissive mode for testing: sudo setenforce 0 (don't forget to re-enable it later with sudo setenforce 1 if this fixes the issue, then create a proper policy).

5. Enable Verbose PJSIP Logging

To get deeper insight into what's happening, crank up PJSIP's log level to DEBUG. This will show you exactly when the registration request is sent, what's in it, and whether any response (or error) comes back. Add this to your code before initializing the endpoint:

epConfig.logConfig.level = 5  # DEBUG level (0-5, higher = more verbose)
epConfig.logConfig.consoleLevel = 5

Look for lines showing the registration request being sent, and check for indicators of packet loss, invalid headers, or network errors.

6. Test with Another SIP Client

If all the above checks come up empty, try registering the same SIP account using a different client (like Linphone, Zoiper, or a web-based SIP client). If that client also gets a 408 timeout, the issue is definitely with the SIP server or your network connection to it. If the other client works, the problem is isolated to your PJSIP code or configuration.


内容的提问来源于stack exchange,提问作者Raady

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 04:17:47