コード例 #1
0
 private void _server_SocketConnected(System.Net.Sockets.Socket socket)
 {
     try
     {
         //设置接收标志位
         _recevingFlag = true;
         ////配置Socket的Timeout
         //socket.ReceiveTimeout = SOCKET_RECEIVE_TIMEOUT;
         //获取消息头
         string headMsg = socket.GetHeadMsg(16);
         //根据消息头处理
         ReceiveContext context = new ReceiveContext(headMsg);
         context.Process(socket);
         //回复接收标志位
         _recevingFlag = false;
     }
     catch (SocketException se)
     {
         //回复接收标志位
         _recevingFlag = false;
         string msg = string.Format("本地接收远端套接字的发送数据时,发生套接字异常!SocketException ErrorCode:{0}", se.ErrorCode);
         _logger.Error(msg);
         LogHelper.Instance.ErrorLogger.Add(new ErrorLogEntity(DateTime.Now, "ERROR", msg));
         socket.CloseSocket();
         string.Format("{0}:本地接收数据时发生套接字异常!套接字错误码:{1}", DateTime.Now, se.ErrorCode).RefreshUINotifyText();
     }
     catch (Exception e)
     {
         //回复接收标志位
         _recevingFlag = false;
         string msg = string.Format("本地接收远端套接字的发送数据时,发生异常!异常为:{0}", e.Message);
         _logger.Error(msg);
         LogHelper.Instance.ErrorLogger.Add(new ErrorLogEntity(DateTime.Now, "ERROR", msg));
         socket.CloseSocket();
         string.Format("{0}:本地接收数据时发生异常!", DateTime.Now).RefreshUINotifyText();
     }
 }