Exemplo n.º 1
0
        private void ClientThread(object o)
        {
            TcpClient    client = (TcpClient)o;
            BinaryReader br     = new BinaryReader(client.GetStream());

            while (!_stopClients)
            {
                try
                {
                    HRDMessageBlock msg = HRDMessage.BytesToHRDMessage(br);

                    if (msg.nSize == 0)
                    {
                        break;
                    }

                    HRDTCPEventArgs e = new HRDTCPEventArgs(client, msg);

                    if (HRDTCPEvent != null)
                    {
                        HRDTCPEvent(this, e);
                    }
                }
                catch
                {
                }
            }
            _parent.SetNotifyIconText("MiniDeluxe - Running (" + --_connectionCount + " connections)");
        }
Exemplo n.º 2
0
        public static byte[] HRDMessageToByteArray(String szText)
        {
            // create HRD message
            HRDMessageBlock msg = new HRDMessageBlock
              {
                  nChecksum = 0,
                  nSanity1 = 0x1234ABCD,
                  nSanity2 = 0xABCD1234,
                  szText = Encoding.Unicode.GetBytes(szText + "\0"),
                  nSize = (uint)Encoding.Unicode.GetByteCount(szText + "\0") + (sizeof(uint) * 4)
              };

            #if DEBUG
            //MiniDeluxe.Debug(String.Format("TX: {0}", szText));
            #endif
            // Serialize it
            int len = (int)msg.nSize;
            byte[] buf = new byte[len];
            Array.Copy(BitConverter.GetBytes(msg.nSize), 0, buf, 0, 4);
            Array.Copy(BitConverter.GetBytes(msg.nSanity1), 0, buf, 4, 4);
            Array.Copy(BitConverter.GetBytes(msg.nSanity2), 0, buf, 8, 4);
            Array.Copy(BitConverter.GetBytes(msg.nChecksum), 0, buf, 12, 4);
            Array.Copy(msg.szText, 0, buf, 16, msg.szText.Length);
            return buf;
        }
Exemplo n.º 3
0
        public static byte[] HRDMessageToByteArray(String szText)
        {
            // create HRD message
            HRDMessageBlock msg = new HRDMessageBlock
            {
                nChecksum = 0,
                nSanity1  = 0x1234ABCD,
                nSanity2  = 0xABCD1234,
                szText    = Encoding.Unicode.GetBytes(szText + "\0"),
                nSize     = (uint)Encoding.Unicode.GetByteCount(szText + "\0") + (sizeof(uint) * 4)
            };

#if DEBUG
            //MiniDeluxe.Debug(String.Format("TX: {0}", szText));
#endif
            // Serialize it
            int    len = (int)msg.nSize;
            byte[] buf = new byte[len];
            Array.Copy(BitConverter.GetBytes(msg.nSize), 0, buf, 0, 4);
            Array.Copy(BitConverter.GetBytes(msg.nSanity1), 0, buf, 4, 4);
            Array.Copy(BitConverter.GetBytes(msg.nSanity2), 0, buf, 8, 4);
            Array.Copy(BitConverter.GetBytes(msg.nChecksum), 0, buf, 12, 4);
            Array.Copy(msg.szText, 0, buf, 16, msg.szText.Length);
            return(buf);
        }
Exemplo n.º 4
0
        public static HRDMessageBlock BytesToHRDMessage(BinaryReader br)
        {
            HRDMessageBlock msg = new HRDMessageBlock();

            try
            {
                msg.nSize = br.ReadUInt32();
                msg.nSanity1 = br.ReadUInt32();
                msg.nSanity2 = br.ReadUInt32();
                msg.nChecksum = br.ReadUInt32();
                msg.szText = br.ReadBytes((int)msg.nSize - (sizeof(UInt32) * 4));
                return msg;
            }
            catch
            {
                msg.nSize = 0;
                return msg;
            }
        }
Exemplo n.º 5
0
        public static HRDMessageBlock BytesToHRDMessage(BinaryReader br)
        {
            HRDMessageBlock msg = new HRDMessageBlock();

            try
            {
                msg.nSize     = br.ReadUInt32();
                msg.nSanity1  = br.ReadUInt32();
                msg.nSanity2  = br.ReadUInt32();
                msg.nChecksum = br.ReadUInt32();
                msg.szText    = br.ReadBytes((int)msg.nSize - (sizeof(UInt32) * 4));
                return(msg);
            }
            catch
            {
                msg.nSize = 0;
                return(msg);
            }
        }
Exemplo n.º 6
0
        public static HRDMessageBlock BytesToHRDMessage(BinaryReader br)
        {
            HRDMessageBlock msg = new HRDMessageBlock();

            try
            {
                msg.nSize     = br.ReadUInt32();
                msg.nSanity1  = br.ReadUInt32();
                msg.nSanity2  = br.ReadUInt32();
                msg.nChecksum = br.ReadUInt32();
                msg.szText    = br.ReadBytes((int)msg.nSize - (sizeof(UInt32) * 4));
//                MiniDeluxe.Debug("RX Header:" + msg.nSize.ToString("x8") + ":" + msg.nSanity1.ToString("x8") + ":" + msg.nSanity2.ToString("x8") + ":" + msg.nChecksum.ToString("x8"));
                return(msg);
            }
            catch
            {
                msg.nSize = 0;
                return(msg);
            }
        }
Exemplo n.º 7
0
        public static byte[] HRDMessageToByteArray(String szText, bool logBook = false)
        {
            // create HRD message


            HRDMessageBlock msg = new HRDMessageBlock
            {
                nChecksum = 0,

                nSanity1 = 0x1234ABCD,
                nSanity2 = 0xABCD1234,

                szText = Encoding.Unicode.GetBytes(szText + "\0"),
                nSize  = (uint)Encoding.Unicode.GetByteCount(szText + "\0") + (sizeof(uint) * 4)
            };

            if (logBook)
            {
                msg.nSanity1 = 0xc0defeed;
                msg.nSanity2 = 0xdeefed0c;
            }
#if DEBUG
//            MiniDeluxe.Debug("TX Header:" + msg.nSize.ToString("x8") + ":" + msg.nSanity1.ToString("x8") + ":" + msg.nSanity2.ToString("x8") + ":" + msg.nChecksum.ToString("x8"));
//                        MiniDeluxe.Debug(String.Format("TX:{0}", szText));
#endif


            int    len = (int)msg.nSize;
            byte[] buf = new byte[len];
            Array.Copy(BitConverter.GetBytes(msg.nSize), 0, buf, 0, 4);
            Array.Copy(BitConverter.GetBytes(msg.nSanity1), 0, buf, 4, 4);
            Array.Copy(BitConverter.GetBytes(msg.nSanity2), 0, buf, 8, 4);
            Array.Copy(BitConverter.GetBytes(msg.nChecksum), 0, buf, 12, 4);



            Array.Copy(msg.szText, 0, buf, 16, msg.szText.Length);

            return(buf);
        }
Exemplo n.º 8
0
 public HRDTCPEventArgs(TcpClient client, HRDMessageBlock msg)
 {
     Client = client;
     Message = msg;
 }
Exemplo n.º 9
0
 public HRDTCPEventArgs(TcpClient client, HRDMessageBlock msg)
 {
     Client  = client;
     Message = msg;
 }