/// <summary> /// Handles the client. /// </summary> /// <param name="client">The client.</param> public void HandleClient(TcpClient client) { Console.WriteLine("started the server"); Task task = new Task(() => { NetworkStream stream = client.GetStream(); BinaryReader reader = new BinaryReader(stream); BinaryWriter writer = new BinaryWriter(stream); while (true) { try { string commandLine = reader.ReadString(); Console.WriteLine("Got command: {0}", commandLine); string result = controller.ExecuteCommand(commandLine, client); if (result.Contains("close") || result.Contains("deleted")) { break; } Console.WriteLine(result); writer.Write(result); writer.Flush(); } catch { this.controller.ExecuteCommand("close", client); } } }); task.Start(); }
public void HandleClient(TcpClient client) { Task task = new Task(() => { NetworkStream stream = client.GetStream(); BinaryReader reader = new BinaryReader(stream); BinaryWriter writer = new BinaryWriter(stream); while (true) { string commandLine = reader.ReadString(); string result = controller.ExecuteCommand(commandLine, client); if (commandLine.Contains("generate") || commandLine.Contains("solve") || commandLine.Contains("list")) { writer.Write(result); break; } if (commandLine.Contains("join")) { writer.Write(result); } if (result == "close") { break; } } client.Close(); }); task.Start(); }