private void button3_Click(object sender, EventArgs e) { IPEndPoint host = new IPEndPoint(IPAddress.Any, 8888); IPEndPoint remote = new IPEndPoint(IPAddress.Any, 7777); Msg m = new Msg(remote, "zz", "zhujun", Commands.Entry, "test1", "test2"); m.PackageNo = 12345678; PacketNetWorkMsg[] udps = MessagePacker.BuildNetworkMessage(m); PacketNetWorkMsg p = MessagePacker.Parse(udps[0].Data, null); Msg ms = MessagePacker.TryToTranslateMessage(p); }
/// <summary> /// 异步分包发送数组的方法 /// </summary> /// <param name="message"></param> public void AsyncSendMsg(Msg message) { if (IsInitialized) { ICollection <PacketNetWorkMsg> udpPackets = MessagePacker.BuildNetworkMessage(message); foreach (PacketNetWorkMsg packedMessage in udpPackets) { //使用异步的方法发送数据 AsyncSendPacket(packedMessage); } } }