none
Unable to decode SAP/SDP data using UdpClient when streaming video remotely RRS feed

  • Question

  • I'm not able to decode UDP packets containing SAP/SDP data associated with streaming video to a multicast IP address (224.2.127.254:4001) from VLC Media Player 1.1.9 -- that is, sending the video and announcements between 2 machines on the same subnet. I'm using the UdpClient from System.Net.Sockets to receive the data, and when I attempt to decode the byte array with Encoding.UTF8.GetString, it just returns a garbled string.  Perhaps it's encrypted?

    When I setup VLC to run on the same machine as my development environment (VS2012) and stream the video to the same multicast IP address, I have no problem decoding the SDP document associated with the SAP announcement, which is great, but I need to make this work in a networked configuration.

    Here's the code for creating the UdpClient:

    private string _ipAddress; // << assigned 224.2.127.254 elsewhere

    private string _port; // << assigned 4001 elsewhere

    private UdpClient _udpClient = null;

    public void Connect()

    {

        // open session for SAP announcements based on IP address and port number provided.

        _udpClient = new UdpClient(Convert.ToInt32(_port));

        _udpClient.JoinMulticastGroup(System.Net.IPAddress.Parse(_ipAddress));

        _udpClient.MulticastLoopback = false;

        _listenerThread = new Thread(Listen);

        _listenerThread.Start();

    }

    private void Listen()

    {

            IPEndPoint ipEndpoint = null;

            ipEndpoint = new IPEndPoint(System.Net.IPAddress.Any, 0);

            // we continue listening indefinitely until this thread is joined when the listener is disconnected or disposed

            while (true)

            {

                       // this line returns a garbled string:

                byte[] data = _udpClient.Receive(ref ipEndpoint); 

                if (data != null)

                {

                    string message = Encoding.UTF8.GetString(data);

                    ...

                }

                Thread.Sleep(10000);

            }

    }

    Any recommendations on what I need to do differently to decode those UDP packets with my SAP/SDP announcements from VLC?

    Thanks -

    Kevin

    Friday, June 7, 2013 10:48 PM

Answers