Ejemplo n.º 1
0
        public static void DisposeClient(MemTcpClient client)
        {
            if (client == null)
            {
                return;
            }
            try
            {
                bool exists = false;

                lock (_clients)
                {
                    exists = _clients.Remove(client);
                }

                if (exists)
                {
                    client.LogManager.Info("NetworkGateway.DisposeClient()", "\tDisposing " + client.Protocol + "client");
                    client.Dispose();
                }
            }
            catch (Exception e)
            {
                LogManager.Logger.Fatal("NetworkGateway.DisposeClient()", "\tFailed to dispose MemTcpClient. " + e.Message);
            }
        }
Ejemplo n.º 2
0
        private void OnClientConnected(IAsyncResult ar)
        {
            TcpClient client = null;
            try
            {
                client = _listener.EndAcceptTcpClient(ar);

                try
                {
                    _listener.BeginAcceptTcpClient(new AsyncCallback(OnClientConnected), null);
                }
                catch (System.Net.Sockets.SocketException e)
                {
                    LogManager.Logger.Fatal("TcpNetworkGateway.OnClientConnected()", "\t Failed to accept TcpClients. " + e.Message);
                    throw;
                }
                catch (Exception ex)
                {
                    LogManager.Logger.Fatal("TcpNetworkGateway.OnClientConnected()", "\t Failed to accept TcpClients. " + ex.Message);
                    throw;
                }

                MemTcpClient clientHandler = new MemTcpClient(client, _protocol);
                lock(_clients)
                    _clients.Add(clientHandler);
                clientHandler.Start();
            }
            catch (Exception e)
            {
                string clientName = "";
                if (client != null)
                {
                    clientName = client.Client.RemoteEndPoint.ToString();
                    clientName = " for " + clientName;
                }
                LogManager.Logger.Fatal("TcpNetworkGateway.OnClientConnected()", "\t Failed to initialize MemTcpClient " + clientName + e.Message+e.StackTrace);

                try
                {
                    client.Close();
                }
                catch (Exception)
                { }
            }
            

        }
Ejemplo n.º 3
0
        private void OnClientConnected(IAsyncResult ar)
        {
            TcpClient client = null;

            try
            {
                client = _listener.EndAcceptTcpClient(ar);

                try
                {
                    _listener.BeginAcceptTcpClient(new AsyncCallback(OnClientConnected), null);
                }
                catch (System.Net.Sockets.SocketException e)
                {
                    LogManager.Logger.Fatal("TcpNetworkGateway.OnClientConnected()", "\t Failed to accept TcpClients. " + e.Message);
                    throw;
                }
                catch (Exception ex)
                {
                    LogManager.Logger.Fatal("TcpNetworkGateway.OnClientConnected()", "\t Failed to accept TcpClients. " + ex.Message);
                    throw;
                }

                MemTcpClient clientHandler = new MemTcpClient(client, _protocol);
                lock (_clients)
                    _clients.Add(clientHandler);
                clientHandler.Start();
            }
            catch (Exception e)
            {
                string clientName = "";
                if (client != null)
                {
                    clientName = client.Client.RemoteEndPoint.ToString();
                    clientName = " for " + clientName;
                }
                LogManager.Logger.Fatal("TcpNetworkGateway.OnClientConnected()", "\t Failed to initialize MemTcpClient " + clientName + e.Message + e.StackTrace);

                try
                {
                    client.Close();
                }
                catch (Exception)
                { }
            }
        }
Ejemplo n.º 4
0
        public static void DisposeClient(MemTcpClient client)
        {
            if (client == null)
                return;
            try
            {
                bool exists = false;

                lock (_clients)
                {
                    exists = _clients.Remove(client);
                }

                if (exists)
                {
                    client.LogManager.Info("NetworkGateway.DisposeClient()","\tDisposing " + client.Protocol + "client");
                    client.Dispose();
                }
            }
            catch (Exception e)
            {
                LogManager.Logger.Fatal("NetworkGateway.DisposeClient()", "\tFailed to dispose MemTcpClient. " + e.Message);
            }
        }
Ejemplo n.º 5
0
 public BinaryProtocolParser(DataStream inputSream, MemTcpClient parent, LogManager logManager)
     : base(inputSream, parent, logManager)
 {
 }
Ejemplo n.º 6
0
 public ProtocolParser(DataStream inputStream, MemTcpClient parent, LogManager logManager)
 {
     _inputDataStream = inputStream;
     _memTcpClient = parent;
     _logManager = logManager;
 }