protected override void ThreadRun() { Socket clientSocket; IPEndPoint ep = new IPEndPoint(settings.IPAddress, settings.Port); try { clientSocket = socket.Accept(); } catch (Exception e) { Console.WriteLine(e); return; } if (clientSocket == null) { return; } ConnectedClient client = new ConnectedClient(); client.socket = clientSocket; client.stream = new NetworkStream(clientSocket); server.RestartStream(delegate() { clients.Add(client); }); }
/// <summary> /// Closes any sockets or streams associated with the client. It's safe /// to kill a client more than once. /// </summary> /// <param name="client"></param> public void KillClientFinish(ConnectedClient client) { if (client.socket == null) { return; } try { client.socket.Close(); client.socket.Dispose(); } catch (Exception e) { Console.WriteLine(e); } client.socket = null; client.stream = null; }
/// <summary> /// Mark a client as killed. The socket and other resources will be /// destroyed soon after. It's okay to kill a client more than once. /// </summary> /// <param name="client"></param> public void KillClient(ConnectedClient client) { lock (killList) { if (client.killed) { return; } killList.Add(client); client.killed = true; outputBuffers.Pulse(); } }