private void HandleMessage(string fullMessage, int code, TcpClient client, ServerWindow console) { string response = null; if (code == 302) { response = Protocol.GetClientResponse(fullMessage); } switch (code) { case 300: client.Send(Protocol.GetResponseFromCode(404)); console.Log("Client sent 300 Response, but no question was asked. 404 No Question sent."); break; case 301: Server.RemoveClient(_username); Server.SendMessage(string.Format("{0} left the chat.", _username), "Server"); console.Log("Client sent 301 Disconnecting. Client removed from list, closing resources."); client.Close(); Thread.CurrentThread.Abort(); break; case 302: new Thread(new ParameterizedThreadStart((tcpClient) => { string respondToClient = this.Parse302Message(response); TcpClient castedClient = (TcpClient)tcpClient; Thread.Sleep(60); castedClient.Send(respondToClient); })).Start(client); break; } }
private void HandleMessage(string fullMessage, int code, TcpClient client, ServerWindow console) { string response = null; if (code == 302) { response = Protocol.GetClientResponse(fullMessage); } switch (code) { case 300: client.Send(Protocol.GetResponseFromCode(404)); console.Log("Client sent 300 Response, but no question was asked. 404 No Question sent."); break; case 301: Server.RemoveClient(_username); console.Log("Client sent 301 Disconnecting. Client removed from list, closing resources."); client.Close(); Thread.CurrentThread.Abort(); break; case 302: Server.SendMessage(string.Join("\n", response), _username); new Thread(new ParameterizedThreadStart((tcpClient) => { // Delay stops two messages being received at the same time and running together Thread.Sleep(60); TcpClient castedClient = (TcpClient)tcpClient; castedClient.Send(Protocol.GetResponseFromCode(201)); })).Start(client); break; } }