Esempio n. 1
0
        //设置用户的udp对象用于发送消息
        UdpLink FindEnvelope(IPEndPoint ep)
        {
            var ip = ep.Address.GetAddressBytes();
            int id = 0;

            unsafe
            {
                fixed(byte *bp = &ip[0])
                id = *(Int32 *)bp;
            }
            for (int i = 0; i < links.Count; i++)
            {
                if (id == links[i].ip)
                {
                    if (ep.Port == links[i].port)
                    {
                        links[i].time = DateTime.Now.Ticks;
                        return(links[i]);
                    }
                }
            }
            UdpLink link = new UdpLink();

            link.ip            = id;
            link.port          = ep.Port;
            link.endpPoint     = ep;
            link.envelope      = new UdpEnvelope();
            link.envelope.type = packType;
            link.time          = DateTime.Now.Ticks;
            links.Add(link);
            return(link);
        }
Esempio n. 2
0
 void EnvelopeCallback(byte[] data, byte tag, UdpLink iP)
 {
     if (auto)
     {
         if (MainDispatch != null)
         {
             MainDispatch(data, tag, iP);
         }
     }
     else
     {
         SocData soc = new SocData();
         soc.data = data;
         soc.tag  = tag;
         soc.obj  = iP;
         lock (queue)
             queue.Enqueue(soc);
     }
 }