internal void Start(IPAddress ipAddress, int port, string type) { TCPListener tcpListener = new TCPListener(ipAddress, port); IAsyncResult tcpAsync; try { tcpListener.Start(); isRunning = true; if (type.Equals("Proxy")) { tcpListener.Server.LingerState = new LingerOption(true, 0); } if (tcpListener.Server.IsBound) { while (isRunning) { try { tcpAsync = tcpListener.BeginAcceptTcpClient(null, null); do { Thread.Sleep(10); if (!isRunning) { break; } }while (!tcpAsync.IsCompleted); TcpClient tcpClient = tcpListener.EndAcceptTcpClient(tcpAsync); object[] parameters = { tcpClient, type, port }; ThreadPool.QueueUserWorkItem(new WaitCallback(ReceiveClient), parameters); } catch (Exception ex) { OutputError(ex, type, port); } } } } catch (Exception ex) { OutputError(ex, type, port); } }
internal void Start(IPAddress ipAddress, int port) { TCPListener tcpListener = new TCPListener(ipAddress, port); IAsyncResult tcpAsync; TcpClient tcpClient; Guid guid = Guid.NewGuid(); try { tcpListener.Start(); isRunning = true; if (tcpListener.Server.IsBound) { while (isRunning) { try { tcpAsync = tcpListener.BeginAcceptTcpClient(null, null); do { Thread.Sleep(10); if (!isRunning) { break; } }while (!tcpAsync.IsCompleted); tcpClient = tcpListener.EndAcceptTcpClient(tcpAsync); object[] parameters = { guid, tcpClient, port }; ThreadPool.QueueUserWorkItem(new WaitCallback(ReceiveClient), parameters); } catch (Exception ex) { OutputError(ex, port); } } } } catch (Exception ex) { OutputError(ex, port); } }