diff options
author | crupest <crupest@outlook.com> | 2021-06-08 18:25:36 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2021-06-08 18:25:36 +0800 |
commit | f27bda8e8d7fcfe82ad20d345c63d327ff047b11 (patch) | |
tree | c2ff251ec1b7c769fb8b4d8fde42e8c9cec74978 /computer-network-experiment/client.cpp | |
parent | fcd0d3aaea9b6a312565e95ad191b5bef17dd541 (diff) | |
download | life-f27bda8e8d7fcfe82ad20d345c63d327ff047b11.tar.gz life-f27bda8e8d7fcfe82ad20d345c63d327ff047b11.tar.bz2 life-f27bda8e8d7fcfe82ad20d345c63d327ff047b11.zip |
...
Diffstat (limited to 'computer-network-experiment/client.cpp')
-rw-r--r-- | computer-network-experiment/client.cpp | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/computer-network-experiment/client.cpp b/computer-network-experiment/client.cpp index c206856..73ae52f 100644 --- a/computer-network-experiment/client.cpp +++ b/computer-network-experiment/client.cpp @@ -75,9 +75,12 @@ int Main() { break;
}
- std::string s = SafeReadUntil(client_socket, '\n', rest);
+ std::string data;
+ if (!SafeReadUntil(client_socket, '\n', data, rest)) {
+ PrintErrorMessageAndExit(CRUT("Failed to receive message.\n"));
+ }
- SendOutput(CRUT("Recived a message:\n{}\n"), ConvertCharString(s));
+ SendOutput(CRUT("Recived a message:\n{}\n"), ConvertCharString(data));
}
});
receive_thread.detach();
@@ -89,7 +92,9 @@ int Main() { std::string s;
if (send_queue.read(s)) {
- SafeSend(client_socket, s);
+ if (!SafeSend(client_socket, s)) {
+ PrintErrorMessageAndExit(CRUT("Failed to send message to server."));
+ }
}
}
|