private void SockConnect(IAsyncResult AsyncCall) { //Accept the connection. TcpListener listener = (TcpListener)AsyncCall.AsyncState; Client c = new Client(); c.GetAcceptedSocket(listener.EndAcceptTcpClient(AsyncCall)); ClientContainer.AddClient(c); Start(); }
private void run() { try { Sock.Start(); } catch (SocketException e) { ConsoleEventLog.addEvent(new ConsoleEventError("Socket error.", e), true); MainClass.Stop(); } Sock.Server.ReceiveTimeout = 500; Sock.Server.SendTimeout = 500; Sock.Server.Blocking = false; Sock.Server.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, 1000); while (!endIt) { Client c = new Client(); try { c.GetAcceptedSocket(Sock.AcceptTcpClient()); ClientContainer.AddClient(c); } catch (InvalidOperationException ioe) { } catch (SocketException se) { if (se.SocketErrorCode == SocketError.WouldBlock) { Thread.Sleep(1000); } } } }