Create a simple Rtsp Server

Topics: Question
Dec 30, 2015 at 3:17 AM

I just tried to create a simple Rtsp server as following:
public static void Main(string[] args)
        IPHostEntry ipHostInfo = Dns.GetHostEntry("localhost");
        IPAddress ipAddress = ipHostInfo.AddressList[1];
        using (Rtsp.RtspServer server = new Rtsp.RtspServer(ipAddress, 554))
            server.TryAddMedia(new Media.Rtsp.Server.MediaTypes.RtspSource("Omega", "rtsp://"));

            //Wait for the server to start.
            while (false == server.IsRunning) System.Threading.Thread.Sleep(0);

            while (server.IsRunning) System.Threading.Thread.Sleep(50);
Then, I used VLC to connect to the rtsp uri: "rtsp://". But, it seems not working, can you explain what's wrong in my example code?

Dec 30, 2015 at 3:37 PM
It's hard to say without knowing your networking configuration.

What I would suggest is to use the 'Media.Common.Extensions.Socket.SocketExtensions.GetFirstUnicastIPAddress(System.Net.Sockets.AddressFamily.InterNetwork)' function to get an address and then use that address in the RtspServer constructor with the port you want and then use VLC to access the RtspServer via that port.

E.g. "rtsp://"

You only have to specify the port if your not using port 554, Let me know if you still have issues.
Marked as answer by juliusfriedman on 12/30/2015 at 8:37 AM
Jan 4, 2016 at 2:10 AM
Hi juliusfriedman,

Thanks for your suggestion, but when I tried the function you suggested me to get IPAddress:
IPAddress ipAddress = Media.Common.Extensions.Socket.SocketExtensions.GetFirstUnicastIPAddress(System.Net.Sockets.AddressFamily.InterNetwork);
It returns me, and I got exception when calling server.Start():

"The requested address is not valid in its context"

Do you have any idea what's wrong with my network configuration?

Jan 5, 2016 at 9:09 PM
Obviously I can't tell you to much about your network configuration without getting more info from you but what I can say is that you can run "ipconfig" and determine which IP Addresses are bound on your various network interfaces.

From there you can determine the IP Address you want and use 'System.Net.IPAddress.Parse' to provide that address to the RtspServer constructor.

Hopefully that helps, let me know if you run into anything else.

Marked as answer by juliusfriedman on 1/5/2016 at 2:09 PM