Discussion:
[pjsip] iOS Error: "Address already in use"
Frederik Riedel
8 years ago
Permalink
Hello,

I am using PJSIP for iOS to connect to a hardware SIP interface.
Sometimes it is necessary to terminate a SIP connection and reconnect (for instance, WiFi switched, IP address changed).
The initial connection always works without any problem. However, when I terminate the connection and try to re-establish, I always receive the following error message:
pjsua_core.c !Error creating SIP TCP listener: Address already in use [status=120048]
When I force-quit the app and restart it I can reconnect without any problem. On the iOS Simulator everything works as expected even without restarting the app.

Do you have any idea what I could try to fix this problem?

Best regards,
Frederik
Colin Morelli
8 years ago
Permalink
You're probably tearing down more of the stack than you need to during an
IP address change. However, even still, you should probably re-compile
PJSIP with PJSIP_TCP_TRANSPORT_DONT_CREATE_LISTENER (and the same for TLS
if you use TLS) when running on iOS.

The default behavior of PJSIP is to bind to port 5060 to receive incoming
signaling messages. Chances are there's either a race condition or
something wrong with your teardown process that keeps a hold on that
ephemeral port during your IP change.

However, when running on iOS, this is largely pointless anyway. It's
incredibly unlikely that an iOS device will be connected without a
NAT/firewall in front of it that would block incoming connections anyway.
Having something listen on port 5060 is not going to accomplish much.
Instead, what you generally want to do, is use RFC 5626 for your PJSIP
account. This way, your client registers with a random local ephemeral port
with your SIP server. Once registration is successful, it keeps the
connection open to your SIP proxy. Your proxy should then use the
already-established connection to deliver incoming calls and signaling
messages for active calls.

Ideally, though, you should move away from registrations for iOS devices
entirely. Apple has already deprecated parking background TCP connections
when the app is inactive, and prefers that you use VoIP push notifications
to deliver incoming calls.

Hopefully this is helpful.

Best,
Colin
...
Frederik Riedel
8 years ago
Permalink
Thanks Colin, I tried to enable both PJSIP_TCP_TRANSPORT_DONT_CREATE_LISTENER and PJSIP_TLS_TRANSPORT_DONT_CREATE_LISTENER and recompiled the framework. However, this did not fix my problem, the error message still occurs when trying to reconnect to the system:

pjsua_core.c !Error creating SIP TCP listener: Address already in use [status=120048]

Is there anything else that could help fixing this problem?

Best,
Frederik
...
qiulang
8 years ago
Permalink
We fixed the exactly problem a long time (when we still used pjsip 2.1).
The solution was simple in our case, store thethe_transport So when app uses a different ip, we shut down andpjsip_transport_dec_ref the old one, and set it to NULL.That works for us but I do hope there is a better way to fix it.


Qiulang


原始邮件
发件人:Frederik ***@frogg.io
收件人:pjsip ***@lists.pjsip.org
发送时闎:2017幎4月20日(å‘šå››) 02:20
䞻题:Re: [pjsip] iOS Error: "Address already in use"


Thanks Colin, I tried to enable both PJSIP_TCP_TRANSPORT_DONT_CREATE_LISTENER andPJSIP_TLS_TRANSPORT_DONT_CREATE_LISTENER and recompiled the framework. However, this did not fix my problem, the error message still occurs when trying to reconnect to the system:


pjsua_core.c !Error creating SIP TCP listener: Address already in use [status=120048]


Is there anything else that could help fixing this problem?


Best,
Frederik





Am 10.04.2017 um 16:32 schrieb Colin Morelli ***@gmail.com:


You're probably tearing down more of the stack than you need to during an IP address change. However, even still, you should probably re-compile PJSIP with PJSIP_TCP_TRANSPORT_DONT_CREATE_LISTENER (and the same for TLS if you use TLS) when running on iOS.


The default behavior of PJSIP is to bind to port 5060 to receive incoming signaling messages. Chances are there's either a race condition or something wrong with your teardown process that keeps a hold on that ephemeral port during your IP change.


However, when running on iOS, this is largely pointless anyway. It's incredibly unlikely that an iOS device will be connected without a NAT/firewall in front of it that would block incoming connections anyway. Having something listen on port 5060 is not going to accomplish much. Instead, what you generally want to do, is use RFC 5626 for your PJSIP account. This way, your client registers with a random local ephemeral port with your SIP server. Once registration is successful, it keeps the connection open to your SIP proxy. Your proxy should then use the already-established connection to deliver incoming calls and signaling messages for active calls.


Ideally, though, you should move away from registrations for iOS devices entirely. Apple has already deprecated parking background TCP connections when the app is inactive, and prefers that you use VoIP push notifications to deliver incoming calls.


Hopefully this is helpful.


Best,
Colin


On Mon, Apr 10, 2017 at 10:22 AM, Frederik Riedel ***@frogg.io wrote:

Hello,


I am using PJSIP for iOS to connect to a hardware SIP interface.
Sometimes it is necessary to terminate a SIP connection and reconnect (for instance, WiFi switched, IP address changed).
The initial connection always works without any problem. However, when I terminate the connection and try to re-establish, I always receive the following error message:
pjsua_core.c !Error creating SIP TCP listener: Address already in use [status=120048]
When I force-quit the app and restart it I can reconnect without any problem. On the iOS Simulator everything works as expected evenwithout restarting the app.


Do you have any idea what I could try to fix this problem?


Best regards,
Frederik

_______________________________________________
Visit our blog: http://blog.pjsip.org

pjsip mailing list
***@lists.pjsip.org
http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org




_______________________________________________
Visit our blog: http://blog.pjsip.org

pjsip mailing list
***@lists.pjsip.org
http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org

Loading...