This is difficult to explain. I have written a RTP audio sender and a RTP Receiver which work well, written in Delphi using TIdUDPClient (sender) and TIdUDPServer (receiver). You can just think of these as sending and receiving data via UDP. These are encapsulated within 2 components that are used within larger apps.
The software containing the RTP Sender also has a separate UDP Server for accepting text commands.
In a separate app, which contains the RTP Receiver component, I need to activate the sender by sending a command to the separate UDP Server, eg. "startrtp". Then in the Sender, I read the PeerIP and PeerPort and put these into the RTP Sender component and tell it to send the audio data back to the port that sent the "startrtp" command. I want to use the same IP/port as I sent the command so any router at the receiving end will let this data through since it is expecting 2-way UDP communications, without having to do any port forwarding. I understand the port can be randomly generated by the router at the RTP Server end. But in the receiver app, I'm not sure what port to set the RTP Receiver component to receive the audio data.
After sending "startrtp" to the RTP Sender app, would the sender need to send back a reply with the PeerIP and PeerPort details so I can feed that into the RTP Receiver component? Or is there some way to discover this info from the UDPClient after sending the "startrtp" command? I'm confused how 2-way comms even works over UDP.
I hope I make some sense.
One way of describing it is like handing over control of a 2-way UDP "connection" seemlessly to separate TIdUPDClient/TIdUPDServer components. I know UDP is connectionless so surely this should be possible somehow. I'm just totally confused.
Then in the Sender, I read the PeerIP and PeerPort and put these into the RTP Sender component and tell it to send the audio data back to the port that sent the "startrtp" command. I want to use the same IP/port as I sent the command so any router at the receiving end will let this data through since it is expecting 2-way UDP communications, without having to do any port forwarding.
In order to do that, you will have to get rid of the TIdUDPClient
on the Receiver end, and instead have its listening TIdUDPServer
handle both text sending and audio receiving. You can send out the text commands using the same TIdSocketHandle
object in the TIdUDPServer.Bindings
collection that will be receiving the audio packets and firing the TIdUDPServer.OnUDPRead
event.
If the RTP Sender needs to send a reply to the text command, then you will have to differentiate reply packets from audio packets in the OnUDPRead
event.