Ejemplo n.º 1
0
 void m_tcpManager_OnConnectSuccess(object sender, TcpClientEventArgs e)
 {
     if (OnConnected != null)
     {
         OnConnected(e.Description, null);
     }
 }
Ejemplo n.º 2
0
 void m_tcpManager_OnConnectFail(object sender, TcpClientEventArgs e)
 {
     m_isLogin = false;
     if (OnDisConnected != null)
     {
         OnDisConnected(e.Description, null);
     }
 }
Ejemplo n.º 3
0
        void m_tcpManager_OnReceiveData(object sender, TcpClientEventArgs e)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("Len:" + e.DataSize + ",Data:");
            for (int i = 0; i < e.DataSize; i++)
            {
                sb.Append(e.Data[i].ToString("X2") + " ");
            }

            MyLog4Net.ILogExtension.DebugWithDebugView(MyLog4Net.Container.Instance.Log, "m_tcpManager_OnReceiveData ret:" + sb.ToString());
            if (OnReceiveData != null)
            {
                OnReceiveData(sb.ToString(), null);
            }

            int index = 0;

            while (true)
            {
                if (index > e.DataSize - 1)
                {
                    break;
                }

                if (e.Data[index] == 0x58 && e.Data[index + 1] == 0x44)
                {
                    IntPtr pdata = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(HEAD)));
                    Marshal.Copy(e.Data, 0, pdata, Marshal.SizeOf(typeof(HEAD)));
                    HEAD hd = (HEAD)Marshal.PtrToStructure(pdata, typeof(HEAD));
                    if (!CheckCRC(e.Data))
                    {
                        return;
                    }
                    int    len  = e.Data[index + 3] + (e.Data[index + 4] << 8) - 8;
                    byte[] body = new byte[len];
                    Array.Copy(e.Data, index + 11, body, 0, len);
                    ProcessProtocol(hd, body);
                    index = index + 11 + len + 2;
                }
                else
                {
                    index++;
                }
            }
        }