Example #1
0
        private void ProcessConnect(SocketAsyncEventArgs e)
        {
            e.AcceptSocket = null;

            if (e.SocketError != SocketError.Success)
            {
                SocketUtils.ShutdownSocket(_socket);
                _logger.InfoFormat("Socket connect failed, socketError:{0}", e.SocketError);
                OnConnectionFailed(e.SocketError);
                return;
            }

            _connection = new TcpConnection(_socket, _setting, _receiveDataBufferPool, OnMessageArrived, OnConnectionClosed);

            _logger.InfoFormat("Socket connected, remote endpoint:{0}, local endpoint:{1}", _connection.RemotingEndPoint, _connection.LocalEndPoint);

            OnConnectionEstablished(_connection);

            _waitConnectHandle.Set();
        }
Example #2
0
        private void ProcessConnect(SocketAsyncEventArgs e)
        {
            e.Completed     -= OnConnectAsyncCompleted;
            e.AcceptSocket   = null;
            e.RemoteEndPoint = null;
            e.Dispose();

            if (e.SocketError != SocketError.Success)
            {
                SocketUtils.ShutdownSocket(_socket);
                _logger.ErrorFormat("Client socket connect failed, name: {0}, remotingServerEndPoint: {1}, socketError: {2}", Name, _serverEndPoint, e.SocketError);
                OnConnectionFailed(_serverEndPoint, e.SocketError);
                _waitConnectHandle.Set();
                return;
            }

            Connection = new TcpConnection(Name, _socket, _setting, _receiveDataBufferPool, OnMessageArrived, OnConnectionClosed);

            _logger.InfoFormat("Client socket connected, name: {0}, remotingServerEndPoint: {1}, localEndPoint: {2}", Name, Connection.RemotingEndPoint, Connection.LocalEndPoint);

            OnConnectionEstablished(Connection);

            _waitConnectHandle.Set();
        }
Example #3
0
        private void OnSocketAccepted(Socket socket)
        {
            Task.Factory.StartNew(() =>
            {
                try
                {
                    var connection = new TcpConnection(socket, _setting, _receiveDataBufferPool, OnMessageArrived, OnConnectionClosed);

                    _logger.InfoFormat("Socket accepted, remote endpoint:{0}", socket.RemoteEndPoint);

                    foreach (var listener in _connectionEventListeners)
                    {
                        try
                        {
                            listener.OnConnectionAccepted(connection);
                        }
                        catch (Exception ex)
                        {
                            _logger.Error(string.Format("Notify connection accepted failed, listener type:{0}", listener.GetType().Name), ex);
                        }
                    }
                }
                catch (ObjectDisposedException) { }
                catch (Exception ex)
                {
                    _logger.Info("Accept socket client has unknown exception.", ex);
                }
            });
        }
Example #4
0
        private void OnSocketAccepted(Socket socket)
        {
            var connection = new TcpConnection(socket, OnMessageArrived, OnConnectionClosed);

            _logger.InfoFormat("Socket accepted, remote endpoint:{0}", socket.RemoteEndPoint);

            foreach (var listener in _connectionEventListeners)
            {
                try
                {
                    listener.OnConnectionAccepted(connection);
                }
                catch (Exception ex)
                {
                    _logger.Error(string.Format("Notify connection accepted failed, listener type:{0}", listener.GetType().Name), ex);
                }
            }
        }
Example #5
0
        private void ProcessConnect(SocketAsyncEventArgs e)
        {
            e.AcceptSocket = null;

            if (e.SocketError != SocketError.Success)
            {
                SocketUtils.ShutdownSocket(_socket);
                _logger.InfoFormat("Socket connect failed, socketError:{0}", e.SocketError);
                OnConnectionFailed(e.SocketError);
                return;
            }

            _connection = new TcpConnection(_socket, _bufferPool, OnMessageArrived, OnConnectionClosed);

            _logger.InfoFormat("Socket connected, remote endpoint:{0}, local endpoint:{1}", _connection.RemotingEndPoint, _connection.LocalEndPoint);

            OnConnectionEstablished(_connection);

            _waitConnectHandle.Set();
        }
Example #6
0
 public ClientSocket Shutdown()
 {
     if (_connection != null)
     {
         _connection.Close();
         _connection = null;
     }
     else
     {
         SocketUtils.ShutdownSocket(_socket);
         _socket = null;
     }
     return this;
 }