.net 平台下, Socket通讯协议中间件设计思路
发布日期:2021-05-09 09:06:45 浏览次数:16 分类:博客文章

本文共 5262 字,大约阅读时间需要 17 分钟。

.net ������������������������������������������������������������������������������

������ ������������ ������
1 WCF ������������������������������������������������������������
2

���SuperSocket������������

��������������� ������������������������
3 ������������winsocket ������������������������������������������������������������������������������������������������

������������socket���������������������������������������������������������������������������������������������������������������

���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������

���������������������������

������������������������������������������������

������������������������������

  1.  ��������� ������������������������������������������������������������������������������������������������������������
  2. ���������������  .net core������������������������ ������������������c���c++���������������������������������������������������
  3. ������������������ ������������������������������.net���������������������������
  4. ���������������������  ���������������������������������������������������������������

������������

������������������������������.net���������������������������������������������������.net���������������������������������������������

.net���������������������������������������������������������������������������������������������������������������������

���������������������������int���string���short���long���byte���

������������������������: List<int>���List<string>���List<short>���List<long>���byte[];

 

���������������������

 

public class NetPacket    {        public int PacketType { get; set; } // ���������        public int Param1 { get; set; }     // ������1 ���������������������������������        public int Param2 { get; set; }     // ������2 ���������������������������������
public List
Items { get; set; } //���������key value ������ }

 

NetValuePair ���������������
public class NetValuePair    {        public string Key { get; set; }        public NetValueBase Value { get; set; }        public NetValuePair()        {        }    }

���NetValueBase ������������������������������string���int���������string���������������

public class NetValueBase    {        public EN_DataType ValueType { get;protected set; }        public virtual object GetValue()        {            return null;        }    }

������

public class NetValueString: NetValueBase    {        public string Value { get; set; } = string.Empty;        public override object GetValue()        {            return Value;        }        public NetValueString()        {            ValueType = EN_DataType.en_string;        }        public NetValueString(string value)        {            ValueType = EN_DataType.en_string;            Value = value;        }    }
NetValueString��������������������������������������������������������������������������� string���������utf8��������������������������������������������������������������������������������������������������� ������������������������������������������.net ���������������������������������������������������������������������
internal static void WriteStringValue(Stream stream, string value)        {            byte[] bytes = Encoding.UTF8.GetBytes(value);            WriteInt32(stream, bytes.Length);            stream.Write(bytes, 0, bytes.Length);        }

������������������������������������������������������������������������������������������������������

������

������������������������������������������������������������������

���������������������������������������������������������������������������������������������

public class RawNetPacket    {        public static int HeadLen = 14;        public UInt16 PacketLen;        public UInt32 PacketId;   //������������������ ������id        public UInt32 TotalNO;    //������������������        public UInt32 PacketNO;   //������������        public byte[] Body;     //������NetPacket������������������������������������������
}������

 ���������������������������������������������������������

������������

1 ������������

 

private NetPacket GetPacketByFile(string fileName)        {            using (FileStream stream = new FileInfo(fileName).OpenRead())            {                NetPacket result = new NetPacket();                result.PacketType = 2;                result.Param1 = 2;                result.Param2 = 3;                result.Items = new List
(); //string NetValuePair pair = new NetValuePair(); pair.Key = "������������"; pair.Value = new NetValueString(fileName); result.Items.Add(pair); //byte pair = new NetValuePair(); pair.Key = "���������������������"; NetValueListByte fileBuffer = new NetValueListByte(); fileBuffer.Value = new byte[stream.Length]; stream.Read(fileBuffer.Value, 0, Convert.ToInt32(stream.Length)); pair.Value = fileBuffer; result.Items.Add(pair); return result; } }

 

���2 ������������

  ���������������������������json������������������������

 

 

上一篇:使用ffmpeg实现对h264视频解码 -- (实现了一个易于使用的c++封装库)
下一篇:CAD 二次开发 -- 自动加载开发的DLL

发表评论

最新留言

路过,博主的博客真漂亮。。
[***.116.15.85]2025年04月20日 23时10分42秒