Example #1
0
 void m_tcpManager_OnConnectSuccess(object sender, TcpClientEventArgs e)
 {
     if (OnConnected != null)
     {
         OnConnected(e.Description, null);
     }
 }
Example #2
0
 void m_tcpManager_OnConnectFail(object sender, TcpClientEventArgs e)
 {
     m_isLogin = false;
     if (OnDisConnected != null)
     {
         OnDisConnected(e.Description, null);
     }
 }
Example #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"));
            }
            if (OnReceiveData != null)
            {
                OnReceiveData(sb.ToString(), null);
            }

            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[3] + e.Data[4] << 8 - 8;

            byte[] body = new byte[len];
            Array.Copy(e.Data, 11, body, 0, len);
            switch ((EnumProtocolType)hd.messagetype)
            {
            case EnumProtocolType.RET_HEART_BEAT:
                OnReceiveData_HB(body);
                break;

            case EnumProtocolType.RET_USER_LOGIN:
                OnReceiveData_LOGIN(body);
                break;

            case EnumProtocolType.RET_SUBSCTIBR_DEV_STATUS:
                OnReceiveData_SubscribrDevStatus(body);
                break;

            case EnumProtocolType.NOTE_DEV_STATUS:
                OnReceiveData_NoteDevStatus(body);
                break;

            case EnumProtocolType.RET_SUBSCTIBR_DEV_CHARGE_STATUS:
                OnReceiveData_SubscribrDevChargeStatus(body);
                break;

            case EnumProtocolType.NOTE_DEV_CHARGE_STATUS:
                OnReceiveData_NoteDevChargeStatus(body);
                break;

            case EnumProtocolType.RET_GET_DEV_CHARGE_INFO:
                OnReceiveData_GetDevChargeInfo(body);
                break;

            case EnumProtocolType.RET_GET_DEV_VERSION:
                OnReceiveData_GetDevVersion(body);
                break;

            default:
                break;
            }
        }