C# Winform环境下RTSP客户端给服务端发OPTIONS命令

MainForm.CS类 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using jn.isos.socket;
using jn.isos.socket.client;
using jn.isos.socket.common;
namespace jn.isos.video
{
    public partial class MainForm : Form
    {
        private RtspClient m_client;
        private string m_sessionID="";
        private int m_seq;

        public MainForm()
        {
            InitializeComponent();
            m_client = new RtspClient();
            m_client.ReceiveDataEventHandler += ReceiveDataEventHand;
        }
        private void btnLink_Click(object sender, EventArgs e)
        {
            m_client.Open("127.0.0.1", 554);
        }    

        private void btnOptions_Click(object sender, EventArgs e)
        {
            string msg = "OPTIONS " + "rtsp://192.168.43.102/videodevice " + " RTSP/1.0\r\n";
            msg += "CSeq: "+m_seq++ +" \r\n";
            msg += "User-Agent: shawn RTSP options\r\n";
            msg += "\r\n";
            m_client.SendData(msg);
        }

        void ReceiveDataEventHand(string id, string data)
        {
            BeginInvoke(new ReceiveDataCallBack(handleReceiveData), id, data);
        }

        void handleReceiveData(string id, string data)
        {
            txtInfo.Text = data + "\r\n";
            //解析m_sessionID
            int index = txtInfo.Text.IndexOf("Session");
            if (-1 != index)
            {
                String tem = txtInfo.Text.Substring(index, 30);
                int start = tem.IndexOf(' ');
                int end = tem.IndexOf('\r');
                m_sessionID = tem.Substring(start, end - start);
            }
        }

        delegate void ReceiveDataCallBack(string id, string data);            


        private void btnDescrib_Click(object sender, EventArgs e)
        {
            string msg = "DESCRIBE rtsp://192.168.43.102/videodevice RTSP/1.0\r\n";
            msg += "CSeq: " + m_seq++ + "\r\n";
            msg += "Accept: application/sdp\r\n";
            msg += "User-Agent: Lavf59.27.100\r\n";
            msg += "\r\n";
            m_client.SendData(msg);
        }
       

        private void btnSetup_Click(object sender, EventArgs e)
        {
            string msg = "SETUP rtsp://192.168.43.102:554/videodevice/realvideo RTSP/1.0\r\n";
            msg += "Transport: RTP/AVP/TCP;unicast;interleaved=0-1\r\n";
            msg += "CSeq: " + m_seq++ + "\r\n";
            msg += "User-Agent: Lavf59.27.100\r\n";
            msg += "Session: " + m_sessionID + "\r\n";
            msg += "\r\n";
            m_client.SendData(msg);
        }
        
        private void btnPlay_Click(object sender, EventArgs e)
        {
            string msg = "PLAY rtsp://192.168.43.102/videodevice RTSP/1.0\r\n";
            msg += "CSeq: " + m_seq++ + "\r\n";
            msg += "Session: "+m_sessionID+"\r\n";
            msg += "Range: npt=0.000-\r\n";
            msg += "x-dynamic-rate: 1\r\n";
            msg += "User-Agent: QuickTime/7.7.1 (qtver=7.7.1;os=Windows NT 5.1Service Pack 3)\r\n";
            msg += "\r\n";
            m_client.SendData(msg);
        }
       

        private void btnTeardown_Click(object sender, EventArgs e)
        {
            string msg = "TEARDOWN rtsp://192.168.43.102/videodevice RTSP/1.0\r\n";
            msg += "CSeq: " + m_seq++ + "\r\n";
            msg += "Session: " + m_sessionID + "\r\n";         
            msg += "\r\n";
            m_client.SendData(msg);
        }
    }
}

RtspClient.cs类

using jn.isos.socket.common;
using System;
namespace jn.isos.video
{
    public class RtspClient 
    {
        private AsynSocket m_socket;
        public delegate void ReceiveDataEventHand(string id, string data);
        public ReceiveDataEventHand ReceiveDataEventHandler;

        public void Open(string ip, int port)
        {
            try
            {
                m_socket = new AsynSocket();
                m_socket.Role = Role.Client;
                m_socket.Open();
                m_socket.LinkObject.Connect(ip, port);
                m_socket.OnReceive += new AsynSocket.ReceiveStringDataEventHandler(m_socket_OnReceive);
                m_socket.SetKeepAlive(ref m_socket, 5000, 1000);
                m_socket.Receive();
            }
            catch (Exception e)
            {

            }
        }
  
        void m_socket_OnReceive(string id, string data)
        {
            if(ReceiveDataEventHandler != null)
            {
                ReceiveDataEventHandler(id, data);
            }
        }

        public void SendData(string msg)
        {
            m_socket.Send2(msg);
        }
       
    }
}

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
VS2017是微软公司开的一款集成开环境(IDE),用于开各种类型的软件应用程序。它提供了一套完整的工具和功能,方便开人员进行代码编写、调试、测试和部署等工作。 VS2017的优势主要体现在以下几个方面: 首先,VS2017支持多种编程语言,包括C、C++、C#、Python等,使开人员可以根据项目需求选择最适合的语言进行开。同时,VS2017还具备强大的代码编辑功能,如智能代码提示、语法检查等,能够帮助开人员提高代码质量和开效率。 其次,VS2017提供了丰富的调试工具,能够帮助开人员快速定位和修复程序中的bug。开人员可以通过断点调试、查看变量值、单步执行等功能,深入了解程序运行过程,从而加快 bug 的修复进程。 此外,VS2017还支持团队协作开,提供了代码版本控制工具(如Git)、团队项目管理功能等。开人员可以方便地与其他团队成员进行代码的共享与合作,提高开效率和团队协作效果。 最后,VS2017还通过集成了大量的第三方扩展,扩展了其功能和应用范围。开人员可以根据自己的需要,选择并安装适合自己项目的扩展,满足特定的开需求。 综上所述,VS2017作为一款强大的集成开环境,具备多种语言支持、丰富的调试工具、团队协作功能和扩展性等优势,可以帮助开人员更加高效地进行软件开工作。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值