public Listener(int port, ReceivedDataHandler dataHandler = null) { this.client = null; this.port = port; this.server = null; this.stream = null; this.ReceivedData += dataHandler; }
private void HandleConnection(IAsyncResult result) { allDone.Set(); Socket listener = (Socket)result.AsyncState; Socket handler = listener.EndAccept(result); byte[] receivedData = ReceiveData(handler); ReceivedDataHandler?.Invoke(receivedData, handler.RemoteEndPoint.ToString()); handler.Shutdown(SocketShutdown.Both); }