Example #1
0
        public void BroadCastMsg(string msg, int port)
        {
            UDPDATA udpd = new UDPDATA();

            udpd.udp_CmdHead  = 0;
            udpd.udp_isclient = 0;
            udpd.udp_HostID   = 0;
            udpd.udp_Body     = new UdpMessage(msg);
            IPEndPoint mip = new IPEndPoint(IPAddress.Broadcast, port);

            MUSPSend(mip, udpd);
        }
Example #2
0
        public static byte[] UDPDATAToBytes(UDPDATA tosend)
        {
            tosend.udp_Body.SendTime = DateTime.Now;
            byte[] byte_MesageID = BitConverter.GetBytes(tosend.udp_MesageID);
            byte[] byte_head     = BitConverter.GetBytes(tosend.udp_CmdHead);
            byte[] byte_isclient = BitConverter.GetBytes(tosend.udp_isclient);
            byte[] byte_HostID   = BitConverter.GetBytes(tosend.udp_HostID);
            byte[] udp_Body      = tosend.udp_Body.ToBytes();
            byte[] tosenddata    = new byte[byte_MesageID.Length + byte_head.Length + byte_isclient.Length + byte_HostID.Length + udp_Body.Length];

            Array.Copy(byte_MesageID, 0, tosenddata, 0, byte_MesageID.Length);
            Array.Copy(byte_head, 0, tosenddata, byte_MesageID.Length, byte_head.Length);
            Array.Copy(byte_isclient, 0, tosenddata, byte_MesageID.Length + byte_head.Length, byte_isclient.Length);
            Array.Copy(byte_HostID, 0, tosenddata, byte_MesageID.Length + byte_isclient.Length + byte_head.Length, byte_HostID.Length);
            Array.Copy(udp_Body, 0, tosenddata, byte_MesageID.Length + byte_isclient.Length + byte_head.Length + byte_HostID.Length, udp_Body.Length);
            return(tosenddata);
        }
Example #3
0
 public bool MUSPSend(IPEndPoint mip, string msg)
 {
     if (mip == null)
     {
         return(false);
     }
     try
     {
         UDPDATA udpd = new UDPDATA();
         udpd.udp_CmdHead  = 0;
         udpd.udp_isclient = 0;
         udpd.udp_HostID   = 0;
         udpd.udp_Body     = new LhwCode.UdpMessage(msg);
         MUSPSend(mip, udpd);
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Example #4
0
        void ReciveData(IPEndPoint ipend, byte[] MSSG)
        {
            if (MSSG.Length == 0)
            {
                return;
            }
            UDPDATA tmpdata = null;

            try
            {
                tmpdata = DataConver.BytesToUDPDATA(MSSG);
            }
            catch (Exception ee)
            {
                LogHelper.Log(ee.ToString());
            }

            if (tmpdata != null)
            {
                if (tmpdata.udp_MesageID != 0)
                {
                    NeedReply.RemoveAll(delegate(SendActor tm) {
                        return(tm.udpd.udp_MesageID == tmpdata.udp_MesageID);
                    });
                    mMessageID.RemoveID(tmpdata.udp_MesageID);
                }
                tmpdata.IPendpot = ipend;
                if (ShowReceiv)
                {
                    LogHelper.Log("收到:", tmpdata);
                }
                if (HandleMessage != null)
                {
                    HandleMessage(tmpdata);
                }
            }
        }
Example #5
0
        public static UDPDATA BytesToUDPDATA(byte[] res)
        {
            UDPDATA tosend = new UDPDATA();

            byte[] byte_MesageID = BitConverter.GetBytes(tosend.udp_MesageID);
            byte[] byte_head     = BitConverter.GetBytes(tosend.udp_CmdHead);
            byte[] byte_isclient = BitConverter.GetBytes(tosend.udp_isclient);
            byte[] byte_HostID   = BitConverter.GetBytes(tosend.udp_HostID);

            byte[] udp_Body = new byte[res.Length - byte_head.Length - byte_isclient.Length - byte_HostID.Length - byte_MesageID.Length];

            Array.Copy(res, 0, byte_MesageID, 0, byte_MesageID.Length);
            Array.Copy(res, byte_MesageID.Length, byte_head, 0, byte_head.Length);
            Array.Copy(res, byte_MesageID.Length + byte_head.Length, byte_isclient, 0, byte_isclient.Length);
            Array.Copy(res, byte_MesageID.Length + byte_head.Length + byte_isclient.Length, byte_HostID, 0, byte_HostID.Length);
            Array.Copy(res, byte_MesageID.Length + byte_head.Length + byte_isclient.Length + byte_HostID.Length, udp_Body, 0, udp_Body.Length);
            tosend.udp_CmdHead  = BitConverter.ToInt32(byte_head, 0);
            tosend.udp_isclient = BitConverter.ToInt32(byte_isclient, 0);
            tosend.udp_HostID   = BitConverter.ToInt32(byte_HostID, 0);
            tosend.udp_MesageID = BitConverter.ToInt32(byte_MesageID, 0);
            tosend.udp_Body     = new UdpMessage("");
            tosend.udp_Body.GetBody(udp_Body);
            return(tosend);
        }
Example #6
0
        public bool RealMUSPSend(IPEndPoint mip, UDPDATA udpd)
        {
            if (mip == null)
            {
                return(false);
            }
            try
            {
                udpd.udp_Body.SendTime = DateTime.Now;
                byte[] mdata = DataConver.UDPDATAToBytes(udpd);
                mListenCLient.Send(mdata, mdata.Length, mip);
                if (ShowSend)
                {
                    LogHelper.Log("发送", udpd);
                }

                return(true);
            }
            catch (Exception ee)
            {
                LogHelper.Log(ee.ToString());
                return(false);
            }
        }
Example #7
0
 public SendActor(IPEndPoint h, UDPDATA u)
 {
     HostName = h;
     udpd     = u;
 }
Example #8
0
        public void BroadCastMsg(UDPDATA udpd, int port)
        {
            IPEndPoint mip = new IPEndPoint(IPAddress.Broadcast, port);

            MUSPSend(mip, udpd);
        }
Example #9
0
        public void MUSPSend(IPEndPoint mip, UDPDATA udpd)
        {
            SendActor AC = new LhwCode.SendActor(mip, udpd);

            SendQueue.Enqueue(AC);
        }