Exemple #1
0
        private void SendHB()
        {
            HB hb = new HB {
                ClientName = m_userName.ToCharArray(Common.MAX_NAME_LEN), ClientType = (byte)m_userType
            };

            //IntPtr phb = Marshal.AllocHGlobal(Marshal.SizeOf(hb));
            ////System.Net.IPAddress.HostToNetworkOrder()
            //Marshal.StructureToPtr(hb,phb,false);
            //byte[] bhb = new byte[Marshal.SizeOf(hb)];
            //Marshal.Copy(phb, bhb, 0, Marshal.SizeOf(hb));
            ////byte[] hb = new byte[] { 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x01 };
            //Marshal.FreeHGlobal(phb);
            Send(hb, typeof(HB), EnumProtocolType.REQ_HEART_BEAT);
            System.Diagnostics.Trace.WriteLine("SendHB");
        }
Exemple #2
0
        private void OnReceiveData_HB(byte[] data)
        {
            try
            {
                IntPtr pdata = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(HB)));
                Marshal.Copy(data, 0, pdata, Marshal.SizeOf(typeof(HB)));
                HB hb = (HB)Marshal.PtrToStructure(pdata, typeof(HB));

                if (OnReceiveHB != null)
                {
                    OnReceiveHB(hb);
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.ToString());
            }
        }