
本文共 5262 字,大约阅读时间需要 17 分钟。
.net ������������������������������������������������������������������������������
������ | ������������ | ������ |
1 | WCF | ������������������������������������������������������������ |
2 | ���SuperSocket������������ | ��������������� ������������������������ |
3 | ������������winsocket | ������������������������������������������������������������������������������������������������ |
������������socket���������������������������������������������������������������������������������������������������������������
���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
���������������������������
������������������������������������������������
������������������������������
- ��������� ������������������������������������������������������������������������������������������������������������
- ��������������� .net core������������������������ ������������������c���c++���������������������������������������������������
- ������������������ ������������������������������.net���������������������������
- ��������������������� ���������������������������������������������������������������
������������
������������������������������.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 ListItems { 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������������������������
发表评论
最新留言
关于作者
