예제 #1
0
        private void CheckDisconnected()
        {
            if (DateTime.Now.Ticks - _checkDisconnectTime < TimeSpan.TicksPerMillisecond * 500)
            {
                return;
            }

            _checkDisconnectTime = DateTime.Now.Ticks;

            if (!_clientNetManager.IsChannelOpen())
            {
                Disconnect("Timed out, channel closed");
                return;
            }

            if (_clientNetManager.CheckIfTimeout())
            {
                Disconnect("Timed out");
            }
        }
예제 #2
0
        private void AcceptClientAsync(IAsyncResult result)
        {
            if (_tcpListener == null)
            {
                return;
            }

            try {
                var netManager = new GridNetClientManager(_tcpListener.EndAcceptTcpClient(result));
                netManager.GetTcpClient().Client.ReceiveTimeout = _gridServer.Settings.ReceiveTimeout;
                netManager.SetNetHandler(new NetHandlerGridServer(_gridServer, this, netManager));
                Logger.Debug($"Accept client from {netManager.GetTcpClient().Client.RemoteEndPoint as IPEndPoint}");

                var task = new Task(() => {
                    while (netManager.IsChannelOpen())
                    {
                        try {
                            netManager.ChannelRead();
                        } catch (IOException ioerr) {
                            Logger.Error("Unknown exception during packet reading", ioerr);
                        }
                    }
                });
                task.Start();
            } catch (Exception e) {
                if (_isRequestShutdown)
                {
                    return;
                }

                Logger.Error("Unable to accept new network worker client", e);
            } finally {
                try {
                    _tcpListener?.BeginAcceptTcpClient(AcceptClientAsync, null);
                } catch {
                    ;
                }
            }
        }