public static string Setup(DESCRIBE describe_frame,int client_port,int stream_id)
 {
     String command = "SETUP " + describe_frame.ContentBase + describe_frame.Streams[stream_id] + RTSP_CONSTANTS.RTSP_VERSION + Environment.NewLine;
     command += "Transport: RTP/AVP/UDP;unicast;client_port=" + client_port + "-" + (client_port+1) + ";mode=play" + Environment.NewLine;
     command +="CSeq: " + RTSP_CONSTANTS.Cseq++ + Environment.NewLine;
     return command;
 }
        public static string Setup(DESCRIBE describe_frame, int client_port, int stream_id)
        {
            String command = "SETUP " + describe_frame.ContentBase + describe_frame.Streams[stream_id] + RTSP_CONSTANTS.RTSP_VERSION + Environment.NewLine;

            command += "Transport: RTP/AVP/UDP;unicast;client_port=" + client_port + "-" + (client_port + 1) + ";mode=play" + Environment.NewLine;
            command += "CSeq: " + RTSP_CONSTANTS.Cseq++ + Environment.NewLine;
            return(command);
        }
 public static string Play(SETUP setup_frame,DESCRIBE describe_frame,int stream_id)
 {
     String command = "Play " + describe_frame.ContentBase + describe_frame.Streams[stream_id] + RTSP_CONSTANTS.RTSP_VERSION + Environment.NewLine;
     command +="Range:" + describe_frame.Range + Environment.NewLine;
     command +="Session:" + setup_frame.Session + Environment.NewLine;
     command +="CSeq: " + RTSP_CONSTANTS.Cseq++ + Environment.NewLine;
     return command;
 }
        public static string Play(SETUP setup_frame, DESCRIBE describe_frame, int stream_id)
        {
            String command = "Play " + describe_frame.ContentBase + describe_frame.Streams[stream_id] + RTSP_CONSTANTS.RTSP_VERSION + Environment.NewLine;

            command += "Range:" + describe_frame.Range + Environment.NewLine;
            command += "Session:" + setup_frame.Session + Environment.NewLine;
            command += "CSeq: " + RTSP_CONSTANTS.Cseq++ + Environment.NewLine;
            return(command);
        }
        //Completed event args go here
        void RTSP_Socket_EvntArgs_Completed(object sender, SocketAsyncEventArgs e)
        {
            switch (e.LastOperation)
            {
            case SocketAsyncOperation.Connect:
                SendMessage(RTSP_COMMANDS.Describe(YoutubeSource.Source));
                break;

            case SocketAsyncOperation.Send:
                ReceiveMessage();
                break;

            case SocketAsyncOperation.Receive:
                var message         = Encoding.UTF8.GetString(e.Buffer, 0, e.BytesTransferred);
                var Messsage_Status = message.Substring(0, 15);
                if (!Messsage_Status.Contains(RTSP_CONSTANTS.STATUS_OK))
                {
                    throw new WebException(message);
                }
                switch (CurrentCommand)
                {
                case COMMAND.DESCRIBE:
                    DescribeFrame  = new DESCRIBE(message);
                    CurrentCommand = COMMAND.SETUP;
                    SendMessage(RTSP_COMMANDS.Setup(DescribeFrame, UDP_PORT, 0));
                    break;

                case COMMAND.SETUP:
                    SetupFrame     = new SETUP(message);
                    CurrentCommand = COMMAND.PLAY;
                    SendMessage(RTSP_COMMANDS.Play(SetupFrame, DescribeFrame, 0));
                    break;

                case COMMAND.PLAY:
                    PlayFrame = new PLAY(message);

                    iso = IsolatedStorageFile.GetUserStoreForApplication();
                    isf = new IsolatedStorageFileStream("track.aac", System.IO.FileMode.Create, iso);
                    isf.Close();
                    Udp_Socket_EvntArgs.RemoteEndPoint = new IPEndPoint(IPAddress.Any, SetupFrame.Server_RTP_Port);
                    Udp_Socket_EvntArgs.SetBuffer(new byte[MAX_BUFFER_SIZE], 0, MAX_BUFFER_SIZE);
                    UDP_SOCKET.ReceiveFromAsync(Udp_Socket_EvntArgs);
                    break;

                case COMMAND.PAUSE:
                    break;

                case COMMAND.TEARDOWN:
                    SendMessage(RTSP_COMMANDS.Teardown(PlayFrame, SetupFrame));
                    break;
                }
                break;
            }
        }