private void OnConnect(IAsyncResult result) { TcpClient client = serverSocket.EndAcceptTcpClient(result); StreamReader reader = new StreamReader(client.GetStream()); string type = reader.ReadLine(); IRemote remote = null; RemoteConnectEventArgs args = new RemoteConnectEventArgs(); OnRemoteConnect.Call(type, args); if (args.Canceled) { client.Close(); reader.Close(); if (!Server.ShuttingDown) { serverSocket.BeginAcceptTcpClient(new AsyncCallback(OnConnect), null); } return; } try { remote = (IRemote)Activator.CreateInstance(args.Assembly.GetType(type), client); ThreadPool.QueueUserWorkItem(new WaitCallback(remote.Run)); } catch (Exception e) { Logger.LogError(e); if (remote != null) { remote.Disconnect("Caused Error"); } } if (!Server.ShuttingDown) { serverSocket.BeginAcceptTcpClient(new AsyncCallback(OnConnect), null); } }
private void OnConnect(IAsyncResult result) { TcpClient client = serverSocket.EndAcceptTcpClient(result); StreamReader reader = new StreamReader(client.GetStream()); string type = reader.ReadLine(); IRemote remote = null; RemoteConnectEventArgs args = new RemoteConnectEventArgs(); OnRemoteConnect.Call(type, args); if (args.Canceled) { client.Close(); reader.Close(); if (!Server.ShuttingDown) serverSocket.BeginAcceptTcpClient(new AsyncCallback(OnConnect), null); return; } try { remote = (IRemote)Activator.CreateInstance(args.Assembly.GetType(type), client); ThreadPool.QueueUserWorkItem(new WaitCallback(remote.Run)); } catch (Exception e) { Logger.LogError(e); if (remote != null) remote.Disconnect("Caused Error"); } if (!Server.ShuttingDown) serverSocket.BeginAcceptTcpClient(new AsyncCallback(OnConnect), null); }