Exemplo n.º 1
0
        /// <summary>
        /// Waits client connection
        /// </summary>
        /// <param name="handler">Socket handler that will be performed on client connection</param>
        public static void Listen(this TcpListener listener, Action<Socket> handler)
        {
            var client = default(Socket);

            try
            {
                client = listener.AcceptSocket();

                ThreadPool.QueueUserWorkItem(
                    listenerObject => (listenerObject as TcpListener).Listen(handler),
                    listener);

                handler(client);
            }
            finally
            {
                if (client != null) client.Close();
            }
        }
 public static Socket waitForConnection(this TcpListener tcpListener)
 {
     if (tcpListener.notNull())
         return tcpListener.AcceptSocket();
     return null;
 }