Home:ALL Converter>making SIP calls over TCP using PJSIP

making SIP calls over TCP using PJSIP

Ask Time:2013-08-25T10:34:26         Author:John Qualis

Json Formatter

I'm using a PJSIP's pjsua dialer (based on pjsua_app.c, PJSIP 2.0.1) with TCP transport and a SIP trunk to make calls to a mobile phone. The dialer registers with a SIP Server over TCP and also sends out INVITES over TCP. UDP transport is not being used.

The environment is something like this -

PJSIP (behind NAT)<--- SIP over TCP ---> SIP Server <--- SIP trunk --> SIP trunk Provider <-- PSTN/Mobile Gateway-->Mobile phone

All calls are made from PJSIP over TCP to the mobile. To disable UDP transport creation I inserted a line "cfg->no_udp = true;" at the end of the function

"static void default_config(struct app_config *cfg)" in pjsua_app.c

I followed the instructions given here to make calls over TCP.

The problem is that we don't receive audio sent from the mobile end into the PJSIP dialer. But RTP packets from the PJSIP dialer reach the mobile side just fine. We can hear audio in the mobile when the call is established.

We found from packet traces that the reason we dont receive media in the PJSIP dialer is that the SIP server is sending RTP packets received over the SIP trunk to a private IP address.

But when we switch to UDP for registration and send INVITES over TCP the call works fine (audio at both ends).

The wireshark packet capture shows the following -

    1. PJSIP registers with server over TCP.
    2. Server sends 401 with PJ's public IP and port in VIA
    3. PJ registers again but inserts its public ip and port in the 
       contact header in the next REGISTER message sequence.
    So far so good. Same sequence of messages seen when UDP is used to REGISTER.
    4. INVITE sent over TCP. Dialog establishment works fine.
        But in the record-route header nat=yes is missing.
    5. Server sends media to private IP. No media received at PJSIP.

Is this a bug in PJSIP? If so how can this be fixed. Wireshark packet traces are available on request. Your help and inputs are much appreciated.

Author:John Qualis,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/18425121/making-sip-calls-over-tcp-using-pjsip
Shane Powell :

Your question doesn't actually make sense as the transport of the signalling between the sip endpoint and the sip server (either UDP or TCP) has no bearing on the media transport between the two sip endpoints (most likely UDP). So there must be something else going on.\n\nSince your talking about private IP addresses, I'm assuming you are coming from a behind a NAT over the internet to a \"public\" sip server.\n\nIn these types of environments I would recommend you setup STUN, TURN and ICE on the sip endpoint.\n\nI would guess the UDP setup you where talking about has the STUN server setup and the TCP setup you where talking about doesn't.\n\nWithout further information I can't help much more.",
2014-02-22T23:38:16
radu_paun :

Try to use port other than 5060 in both client and server, and/or reducing the SIP message size.\n\nIt seams this is a know issue for sending INVITE request over TCP in PJSIP.\n\nAlso you can find here some advices for reducing the SIP message size.",
2014-05-29T09:01:11
yy