Raady
Raady

Reputation: 1726

pjsua.error, error = address already in use

I am trying to make calls using PJSIP module in python. For setup of SIP transport, I am doing like

trans_cfg = pj.TransportConfig()
# port for VoIP communication
trans_cfg.port = 5060
# local system address
trans_cfg.bound_addr = inputs.client_addr
transport = lib.create_transport(pj.TransportType.UDP,trans_cfg)

when I finish the call I am clearing the transport setup as, transport = None.

I am able to make call to user by running my program. But every time I restart my PC alone, I get an error while I run my python program

File "pjsuatrail_all.py", line 225, in <module>
   main()
File "pjsuatrail_all.py", line 169, in main
   transport = transport_setup()
File "pjsuatrail_all.py", line 54, in transport_setup
   transport = lib.create_transport(pj.TransportType.UDP,trans_cfg)
File "/usr/local/lib/python2.7/dist-packages/pjsua.py", line 2304, in 
   create_transport
   self._err_check("create_transport()", self, err)
File "/usr/local/lib/python2.7/dist-packages/pjsua.py", line 2723, in _err_check
   raise Error(op_name, obj, err_code, err_msg)
pjsua.Error: Object: Lib, operation=create_transport(), error=Address already in use
Exception AttributeError: "'NoneType' object has no attribute 'destroy'" in <bound method Lib.__del__ of <pjsua.Lib instance at 0x7f8a4bbb6170>> ignored

For this currently I am doing like

$sudo lsof -t -i:5060
>> 1137
$sudo kill 1137

Then I run my code it works fine. By instance from error, I can understand that somewhere I am not closing my transport configuration properly. Can anyone help in this regards. Reference code used

Upvotes: 0

Views: 3219

Answers (1)

DKA
DKA

Reputation: 48

From the inputs you give, it can be understood that its not the problem with pjsip wrapper. Transport configurations looks fine.

Looking in to the 'create_transport' error, the program is not able to create the connection because 5060 port is already occupied with some other program.

For that you are killing that process and you are able to run the program with out any error. And you say it only on restart, so on your system restart some program is occupying the port.

You can try like this

sudo netstat -nlp|grep 5060

in your case it will give like

1137/ProgramName

go to the 'ProgramName' in your startup configurations and make modifications such that it wont pickup the port.

Upvotes: 1

Related Questions