Пример #1
0
 public void RecvChange(ListenClient ltClient, byte[] btReceiMsgBuf)//接收到回信息,供监控类回调KD用
 {
     if (OnRecvMsg != null)
     {
         EventArgs_Recv args = new EventArgs_Recv();
         args.btRecevByte = btReceiMsgBuf;
         args.sRecvMsg    = Encoding.Default.GetString(btReceiMsgBuf, 0, btReceiMsgBuf.Length);//接收的信息
         args.sRecvTime   = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
         args.sLogionName = ltClient.strLoginUserName;
         args.sClientIP   = ltClient.ipaEndIP.ToString();
         args.iClientPort = ltClient.intEndPort;
         OnRecvMsg(this, args);
     }
 }
Пример #2
0
        //接收服务器的消息
        void ReceiveMsg()
        {
            while (bRunRecv)
            {
                try
                {
                    byte[] buffer = new byte[MAXSOCKETBUFLEN];
                    int    length = ClientSocket.Receive(buffer);

                    if (length <= 0)
                    {
                        continue;
                    }
                    string strSRecMsg = "";
                    if (OnRecvMsg != null)
                    {
                        EventArgs_Recv args = new EventArgs_Recv();
                        args.btRecvByteBuf = buffer;
                        strSRecMsg         = Encoding.Unicode.GetString(args.btRecvByteBuf);
                        args.sRecvMsg      = strSRecMsg;
                        args.sRecvTime     = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
                        OnRecvMsg(this, args);
                    }
                }
                catch (SocketException ex)
                {
                    Debug.WriteLine(DateTime.Now.ToString("HH:mm:ss,fff") + "  接收服务器的消息失败!" + ex.Message.ToString() + "\t" + ex.ErrorCode.ToString());
                    DisconnectServer();
                    break;
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(DateTime.Now.ToString("HH:mm:ss,fff") + "  接收服务器的消息失败!" + ex.Message.ToString());
                    continue;
                }
            }
        }