I am writing a proxy for an application that uses RTSP for streaming video content. It basically works as follows:
- The application (server) makes an RTSP stream available on localhost port 8554.
- A client wishing to connect to this stream connects to my proxy on localhost port 8553.
- My proxy connects to the RTSP stream (server) on localhost port 8554 and passes the network traffic (bytes) along between client and server. (I don't inspect packets at all, I simply read the bytes on the one stream and pass those bytes along to the other stream.)
Since RTSP uses both TCP and UDP communication, I will have to have listeners for both protocols on the proxy, however, I have not yet got to implementing the UDP part. At the moment I am simply working on TCP which essentially handles the "handshaking" to start the video transfer. The actual video transfer over UDP will be my next step.
Now for my question: I am successfully passing messages ("OPTIONS", "DESCRIBE", "SETUP, etc.) along with the proxy. The problem is that the content of the messages itself contains some information about the streaming server. Specifically, when the server responds to the client's "DESCRIBE" request, it returns amongst others:
Content-Base: rtsp://127.0.0.1:8554/nurv/
Before passing it along to the client, I need to change this on the proxy to:
Content-Base: rtsp://127.0.0.1:8553/nurv/
because at the moment, when the client issues the subsequent "SETUP" request, it requests:
SETUP rtsp://127.0.0.1:8554/nurv/track1 RTSP/1.0
which means that for the actual streaming it bypasses my proxy on port 8553 and connects directly to the stream on 8554.
How can I modify the messages on the proxy so that references to the actual server (i.e. 127.0.0.1:8554) get replaced by references to the proxy (i.e. 127.0.0.1:8553)? Obviously it isn't optimal to do a string search through each message being passed through the proxy since that would mean unpacking and inspecting each message before repacking and sending on.