zoukankan      html  css  js  c++  java
  • RTMP 握手代码C#版

    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Text;
    using FluorineFx;
    using System.Net;
    using System.Net.Sockets;
    using System.ByteBuffer;

    namespace test
    {
        class Program
        {
            public static int HANDSHAKE_SIZE = 1536;
            static void Main(string[] args)
            {
                Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                FluorineFx.Util.UriBase Uri = new FluorineFx.Util.UriBase("rtmp://127.0.0.1:1935/oflaDemo/on2_flash8_w_audio.flv");
                Console.WriteLine(Uri.Host);
                Console.WriteLine(Uri.Port);
                socket.Connect(Uri.Host, Convert.ToInt32(Uri.Port));
             
                byte[] sendbyte = new byte[HANDSHAKE_SIZE+1];
                sendbyte[0] = 0x03;
                socket.Send(sendbyte,HANDSHAKE_SIZE+1,0);

                byte[] buffer = new byte[HANDSHAKE_SIZE*2+1];
                
                int n=socket.Receive(buffer,buffer.Length,0);
                Console.WriteLine(buffer.Length);
             
                string Receive = System.Text.Encoding.ASCII.GetString(buffer,0, buffer.Length);
                Console.WriteLine(Receive);
          
                
                Console.Read();
            }
        }
    }




    RTMP真正完成握手操作是分两步:
    一、建立连接,SOCKET接收到长度为1537byte的数据,注意1536是握手的关键值
    HandshakeSize = 1536;
    ByteBuffer hs = ByteBuffer.Allocate(2 * HandshakeSize + 1);
    hs.Put(0×03);
    hs.Fill((byte)0×00, HandshakeSize);
    context.Stream.Get();// skip the header byte
    ByteBuffer.Put(hs, context.Stream, HandshakeSize);
    hs.Flip();
    这段代码不用看,是我程序里的
    接收到1537byte
    byte[] data=”1537byte的数据”;
    byte[] reData=new byte[3073];//2 * HandshakeSize + 1
    reData[0]=0×03;
    之后,将data写入reData 从 1537 位置开始
    送回,收工
    第二步: 接收客户端信息:
    这儿进行了AMF编码,解码后得到数据,原来是客户端调用服务器端方法connect,同时传过来一个对象(键值对)
  • 相关阅读:
    700. Search in a Binary Search Tree
    100. Same Tree
    543. Diameter of Binary Tree
    257. Binary Tree Paths
    572. Subtree of Another Tree
    226. Invert Binary Tree
    104. Maximum Depth of Binary Tree
    1、解决sublime打开文档,出现中文乱码问题
    移植seetafaceengine-master、opencv到ARM板
    ubuntu16.04-交叉编译-SeetaFaceEngine-master
  • 原文地址:https://www.cnblogs.com/hyruur/p/2091081.html
Copyright © 2011-2022 走看看