Exemplo n.º 1
0
        public Msg ResolveToMessage(byte[] buffer, IPEndPoint remoteEndPoint)
        {
            if (buffer == null || buffer.Length < 0)
            {
                return(null);
            }
            Msg m = null;

            if (MessagePacker.Test(buffer))
            {
                PacketNetWorkMsg pack = MessagePacker.Parse(buffer, remoteEndPoint);
                if (pack == null)
                {
                    return(null);
                }
                if (DetermineConfirm(pack))
                {
                    //发送确认标志
                    Msg cm = Helper.CreateRecivedCheck(remoteEndPoint, pack.PackageNo, pack.PackageIndex, _config);
                    Client.SendMsg(cm);
                }
                m = MessagePacker.TryToTranslateMessage(pack);
            }
            return(m);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
 /// <summary>
 /// 异步将将已经打包的消息发送出去,不进行发送检查
 /// </summary>
 /// <param name="packet"></param>
 public void AsyncSendPacket(PacketNetWorkMsg packet)
 {
     //使用异步的方法发送数据
     if (IsInitialized)
     {
         if (!IsConnect)
         {
             this.client.BeginSend(packet.Data, packet.Data.Length, packet.RemoteIP, new AsyncCallback(SendCallback), null);
         }
         else
         {
             this.client.BeginSend(packet.Data, packet.Data.Length, new AsyncCallback(SendCallback), null);
         }
         if (packet.IsRequireReceiveCheck)
         {
             PushSendItemToList(packet);//将该消息压入列表
         }
     }
 }
Exemplo n.º 4
0
 /// <summary>
 /// 将已经打包的消息发送出去
 /// </summary>
 /// <param name="packet"></param>
 public void SendPacket(PacketNetWorkMsg packet)
 {
     if (IsInitialized)
     {
         //使用同步的方法发送数据
         if (!IsConnect)
         {
             client.Send(packet.Data, packet.Data.Length, packet.RemoteIP);
         }
         else
         {
             client.Send(packet.Data, packet.Data.Length);
         }
         if (packet.IsRequireReceiveCheck)
         {
             PushSendItemToList(packet);
         }
     }
 }
Exemplo n.º 5
0
 /// <summary>
 /// 将数据信息压入列表
 /// </summary>
 /// <param name="item"></param>
 public void PushSendItemToList(PacketNetWorkMsg item)
 {
     SendList.Add(item);
 }
Exemplo n.º 6
0
 /// <summary>
 /// 检测是否需要发送回复包来确认收到
 /// </summary>
 /// <param name="message"></param>
 /// <returns></returns>
 static bool DetermineConfirm(PacketNetWorkMsg packet)
 {
     return(packet.IsRequireReceiveCheck);
 }
Exemplo n.º 7
0
 public PackageEventArgs(PacketNetWorkMsg udpp, IPEndPoint remotetip)
 {
     // TODO: Complete member initialization
     this.PacketMsg = udpp;
     this.RemoteIP  = remotetip;
 }
Exemplo n.º 8
0
 public PackageEventArgs(PacketNetWorkMsg udpp)
 {
     IsHandled      = false;
     this.PacketMsg = udpp;
 }