public void SocketStartListening() { IPEndPoint localEndPoint = new IPEndPoint(ipAddress, iPortNo); Socket listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); try { listener.Bind(localEndPoint); listener.Listen(100); //listener.Listen(SocketOptionName.MaxConnections ); while (true) { // Set the event to nonsignaled state. allDone.Reset(); // Start an asynchronous socket to listen for connections. Console.WriteLine("SocketUtility::Waiting for a connection at port {0}", iPortNo); SocketListenState socketListenState = new SocketListenState(listener, allDone, appState); listener.BeginAccept(callbackListener, socketListenState); // Wait until a connection is made before continuing. allDone.WaitOne(); } } catch (Exception e) { Console.WriteLine(e.ToString()); } }
public void SocketStartListening() { IPEndPoint localEndPoint = new IPEndPoint(ipAddress, iPortNo); Socket listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp ); try { listener.Bind(localEndPoint); listener.Listen(100); //listener.Listen(SocketOptionName.MaxConnections ); while (true) { // Set the event to nonsignaled state. allDone.Reset(); // Start an asynchronous socket to listen for connections. Console.WriteLine("SocketUtility::Waiting for a connection at port {0}", iPortNo); SocketListenState socketListenState = new SocketListenState(listener, allDone, appState); listener.BeginAccept(callbackListener,socketListenState); // Wait until a connection is made before continuing. allDone.WaitOne(); } } catch (Exception e) { Console.WriteLine(e.ToString()); } }