示例#1
0
        internal void ProcessAccept(SocketAsyncEventArgs AcceptEventArgs)
        {
            Log.Debug("Connect From " + AcceptEventArgs.AcceptSocket.RemoteEndPoint.ToString());
            if (AcceptEventArgs.SocketError != SocketError.Success)
            {
                if (AcceptEventArgs.AcceptSocket != null)
                {
                    AcceptEventArgs.AcceptSocket.Close();
                }
                AcceptLoop(AcceptEventArgs);
                return;
            }
            Socket ClientSocket = AcceptEventArgs.AcceptSocket;
            //TooManyClients(ClientSocket);
            TcpMessageChannel channel = _ChannelManager.Pop();

            if (channel == null)
            {
                TooManyClients(ClientSocket);
            }
            else
            {
                channel.Start(ClientSocket);
            }
            AcceptLoop(AcceptEventArgs);
        }
 public bool Start()
 {
     if (!Connect())
     {
         return(false);
     }
     _TcpMessageChannel.Start(_ClientSocket);
     //MsgChannelGuid MsgGuid = new MsgChannelGuid()
     //{
     //    from = "Client",
     //    to = "server"
     //};
     //MessageHeader reslut = _TcpMessageChannel.SendRecvMessage(MsgGuid);
     return(true);
 }
示例#3
0
 internal void TooManyClients(Socket ClientSocket)
 {
     lock (_ErrorMessageChannel)
     {
         MsgError error = new MsgError()
         {
             error = "连接通道太多,暂时无法提供服务"
         };
         _ErrorMessageChannel.Start(ClientSocket);
         _ErrorMessageChannel.SendMessage(error);
     }
     ClientSocket.Shutdown(SocketShutdown.Both);
     ClientSocket.Close();
     ClientSocket.Dispose();
     ClientSocket = null;
     Log.Warn("连接通道太多");
 }