示例#1
0
        public static TcpListener startListeningForTcpConnections(TcpListenerState.EventProcessor foundConnection, int port = DEFAULT_PORT)
        {
            TcpListener listener = new TcpListener(IPAddress.Any, port);

            listener.Start();

            TcpListenerState newListenerState = new TcpListenerState(listener, foundConnection);

            listener.BeginAcceptSocket(foundTcpConnection, newListenerState);

            return(listener);
        }
示例#2
0
        private static void foundTcpConnection(IAsyncResult ar)
        {
            TcpListenerState ts = (TcpListenerState)ar.AsyncState;

            Socket newSocket = ts.TheTcpListener.EndAcceptSocket(ar);

            SocketState newSocketState = new SocketState(newSocket, (ss) => { });

            newSocketState.SafeToSendRequest = true;

            ts.TheCallback(newSocketState);

            // Starts Listening For Connections
            ts.TheTcpListener.BeginAcceptSocket(foundTcpConnection, ts);
        }