public void StopServer() { if (tcpListener != null) { tcpListener.Stop(); tcpListener = null; } }
public void StartServer(int port) { Port = port; if (tcpListener != null) { tcpListener.Stop(); tcpListener = null; } tcpListener = new TcpListenerActive(IPAddress.Any, port); tcpListener.Start(); tcpListener.BeginAcceptTcpClient(HandleAsyncConnection, tcpListener); }
protected void HandleAsyncConnection(IAsyncResult result) { TcpClient client; try { TcpListenerActive listener = (TcpListenerActive)result.AsyncState; client = listener.EndAcceptTcpClient(result); connectionWaitDone.Set(); tcpListener.BeginAcceptTcpClient(HandleAsyncConnection, listener); Connection clientConnection = new Connection(client); clientConnection.StartLogin(); } catch (Exception e) { string msg = e.Message; } }