public void HandleClient() { try { while (true) { logger.Log("Waiting for user request..."); string request = client.Reader.ReadString(); // blocks here until client sends a request logger.Log("Request: " + request); if (decoder.TryDecodeMessage(request, out ZipRequestMessage decodedZR)) { logger.Log("Decoded message as ZipRequest"); requestHandler.HandleZipRequest(decodedZR); } else if (decoder.TryDecodeMessage(request, out TransferRequestMessage decodedTR)) { logger.Log("Decoded message as TransferRequest"); requestHandler.HandleTransferRequest(decodedTR); } else if (decoder.TryDecodeMessage(request, out ServerInfoRequestMessage decodedSIR)) { logger.Log("Decoded message as ServerInfoRequest"); requestHandler.HandleServerInfoRequest(decodedSIR, categorizationStrategy); } else { SendResponseMessage(ResponseCode.Error, "Invalid message received"); } } } catch (EndOfStreamException) { // disconnected from client } catch (Exception e) { logger.Log(e.ToString()); } finally { client.Client.Close(); logger.Log("Connection with client closed."); } }