private bool CanConnect(IPEndPoint ep) { bool allowed = false; IncomingConnection?.Invoke(ep, out allowed); return(allowed); }
private async Task AwaitConnection(TcpListener tcpListener) { TcpClient client = await tcpListener.AcceptTcpClientAsync(); LogConnection(client); IncomingConnection?.Invoke(this, new IncomingConnectionArgs { Client = client }); }
private void Listen() { while (true) { TcpClient client = listener.AcceptTcpClient(); var connection = new TcpConnection(client); var args = new IncomingConnectionEventArgs { Connection = connection }; IncomingConnection?.Invoke(this, args); } }
private void ListenForConnections(TcpListener listener) { Task.Factory.StartNew(async() => { try { while (isListeningForIncomingConnections) { var client = await listener.AcceptTcpClientAsync(); var reader = new StreamReader(client.GetStream()); var status = reader.ReadLine(); string remoteDestination = status.Split(' ').First(); IncomingConnection?.Invoke(this, new AcceptConnectionEventArgs(client, remoteDestination)); } } finally { listener.Stop(); } }, TaskCreationOptions.LongRunning); }