I have freeswitch with two subscribers registered on it.
For example, A and B.
But B can't listen to TCP and UDP protocols at the same port at the same time. So if I configure B for UDP and call from A to B through freeswitch. And freeswitch tries to connect to B via TCP, then it fails and it sends 503 Service Unavailable to A.
I know about clause 8.1.3.1 in RFC3261. But I'm not sure about it and I want to ask what the SIP standard says about it. Shouldn't you try sending message over UDP if you unable to establish a TCP connection?
I read SIP standard, but I didn't find anything about that(maybe I missed that).
Moreover, I want to know if this is a freeswitch mistake.
2 Answers
From rfc3261:
18.2 Servers
18.2.1 Receiving Requests
A server SHOULD be prepared to receive requests on any IP address, port and transport combination that can be the result of a DNS lookup on a SIP or SIPS URI [4] that is handed out for the purposes of
communicating with that server. In this context, "handing out"
includes placing a URI in a Contact header field in a REGISTER
request or a redirect response, or in a Record-Route header field in
a request or response. A URI can also be "handed out" by placing it
on a web page or business card. It is also RECOMMENDED that a server listen for requests on the default SIP ports (5060 for TCP and UDP,
5061 for TLS over TCP) on all public interfaces. The typical
exception would be private networks, or when multiple server
instances are running on the same host. For any port and interface
that a server listens on for UDP, it MUST listen on that same port
and interface for TCP. This is because a message may need to be sent using TCP, rather than UDP, if it is too large. As a result, the
converse is not true. A server need not listen for UDP on a
particular address and port just because it is listening on that same address and port for TCP. There may, of course, be other reasons why a server needs to listen for UDP on a particular address and port.
In practice, a service in real life MUST listen on all mandatory transport. Otherwise users are getting into troubles.
Anyway, a client will in practice use either UDP or TCP (or TLS). But not both. This should really not be an issue if A and B are using different transport because the service (freeswitch here) should communicate with UDP for A and with TCP for B. Using different transport for each users must not be a reason for a routing failure.
To be complete, SIP servers usually cannot send message to SIP clients without an existing connection (because of NAT, firewall...). SIP clients will usually make a REGISTER (and thus, create a reusable TCP connection or a reusable UDP binding), then, when required, the server will always re-use that TCP connection or UDP binding (so called a reversed path) to forward the new request (the INVITE).
In real world, there is no other way!
If you send a REGISTER request from B with TCP transport in contact header then freeswitch will communicate with TCP else with UDP. For your case, Yes its possible. UAS/UAC can listen in the same port with TCP & UDP. You can create a socket with TCP and UDP in code. Below UAS is listening at UDP & TCP.