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,同时传过来一个对象(键值对)
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,同时传过来一个对象(键值对)