public Listener(int port, ReceivedDataHandler dataHandler = null)
        {
            this.client = null;
            this.port   = port;
            this.server = null;
            this.stream = null;

            this.ReceivedData += dataHandler;
        }
Esempio n. 2
0
        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);
        }