private void ClientConnectedCallback(IAsyncResult ar) { if (!_running) { //listening for connections stopped _stopFinished.SetResult(1); return; } var tcpClient = _tcpListener.EndAcceptTcpClient(ar); log.Trace("incoming connection request"); //prepare for next connect ListenForClients(); //create socket and endpoint for new connection var socket = new Socket(); var endpoint = new Endpoint(socket); socket.Log = Logging.LogManager.GetLogger("Socket " + endpoint.Connection.Id); socket.SetTcpClient(tcpClient); log.Debug("connection request " + endpoint.Connection); //start endpoint message receiver endpoint.ReceiveThread = new Thread(() => { ReceiveHandler(endpoint); }); endpoint.ReceiveThread.Start(); endpoint.Disconnected += Endpoint_Disconnected; _ = ConnectionHandler.ProcessEndpoint(endpoint.Connection, EndpointChangedEventArgs.NewConnection(endpoint)); }
private void ClientConnectedCallback(IAsyncResult ar) { if (!_running) { //listening for connections stopped _stopFinished.SetResult(); return; } var tcpClient = _tcpListener.EndAcceptTcpClient(ar); log.Trace("incoming connection request"); //prepare for next connect ListenForClients(); //create socket and endpoint for new connection var socket = new PacketSocket(tcpClient); var endpoint = new Endpoint(socket); log.Debug("connection request " + endpoint.Connection); var actionBlock = new ActionBlock <Tuple <IEndpoint, byte[]> >(ReceiveHandler); endpoint.MessageBlock.LinkTo(actionBlock); endpoint.Disconnected += Endpoint_Disconnected; _ = ConnectionHandler.ProcessEndpoint(endpoint.Connection, EndpointChangedEventArgs.NewConnection(endpoint)); }
private void Endpoint_Disconnected(object sender, DisconnectedArgs e) { log.Debug("endpoint disconnected " + ((IEndpoint)sender).Connection); ConnectionHandler.ProcessEndpoint(((IEndpoint)sender).Connection, EndpointChangedEventArgs.Disconnect((IEndpoint)sender, e)).Wait(); }