private async Task RunAcceptLoopAsync() { try { while (true) { var acceptSocket = await _listenSocket.AcceptAsync(); acceptSocket.NoDelay = true; var protocol = _protocolFactory.CreateProtocol(); var connection = new ClientConnection(protocol, _pipeline, acceptSocket); _ = HandleConnectionAsync(connection); if (protocol.ResponseOnConnection != null) { var result = this.SendResponse(connection, protocol.ResponseOnConnection); if (result == PipelineResult.StopAndDisconnect) { connection.Disconnect(); } } } } catch (SocketException) when(!_unbinding) { } }
public void NewMessage(PlayerUnreadCount playerUnreadCount) { IPlayer player; locker.Lock((uint)playerUnreadCount.Id, out player).Do(() => { if (player.Session == null) { return; } try { protocolFactory.CreateProtocol(player.Session).MessageSendUnreadCount(playerUnreadCount.UnreadCount); } catch { } }); }
private void StartDispatcher() { _tcpListener.Start(); Socket clientSocket = _tcpListener.AcceptSocket(); IProtocol protocol = _protocolFactory.CreateProtocol(clientSocket, _logger, _dataSource); Thread thread = new Thread(new ThreadStart(protocol.HandleClient)); thread.Start(); _logger.WriteEntry("Created and started Thread: " + thread.GetHashCode()); }