1
votes

Headers of UDP and TCP data are different. I have a use case, where I want to transfer the RTP media stream. Where first choice is UDP and then TCP.

Now imagine that the RTP packet is received to a local UDP port. This local machine attempts a connection with server using UDP first. If it's successful, then no further queries.

But if UDP wasn't possible then we make a TCP connection. Can I relay the local UDP port's data on TCP? Assume that, it will be finally fed to a peer UDP port. Our interest is only for relaying it.

Switch UDP port and TCP connection vice versa. Is that also possible?

1

1 Answers

2
votes

Sure, you could create an explicit relay application which accepts UDP data and forwards these within a TCP connection. And then another relay in the peer which extracts the messages from the TCP connection and forwards these as UDP. This way you basically create a tunnel.

Or you could change your application so that it detects that UDP does not work and uses TCP instead directly, without any kind of relays involved. This is probably the better approach in terms of overhead and needed infrastructure. This has to be explicitly coded into your application though, i.e. different sockets are needed in both sender and recipient and depending on the protocol you might need an additional message encapsulation, since TCP is only a byte stream without message boundaries while UDP has the concept of a message built in. As for RTP: there is already a standard for framing RTP messages when used over protocols like TCP, see RFC 4571.