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 | f7d73f1bf08aaca98e789a6d6c56d672cc0c4c9f (patch) | |
tree | a059a5c93ac38c5826bb59555fa654cebc6ca951 /works/life/computer-network-experiment/client.cpp | |
parent | d9756de78c161c2d33a9d32d2cb1eaa68be1744e (diff) | |
download | crupest-f7d73f1bf08aaca98e789a6d6c56d672cc0c4c9f.tar.gz crupest-f7d73f1bf08aaca98e789a6d6c56d672cc0c4c9f.tar.bz2 crupest-f7d73f1bf08aaca98e789a6d6c56d672cc0c4c9f.zip |
import(life): ...
Diffstat (limited to 'works/life/computer-network-experiment/client.cpp')
-rw-r--r-- | works/life/computer-network-experiment/client.cpp | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/works/life/computer-network-experiment/client.cpp b/works/life/computer-network-experiment/client.cpp index c206856..73ae52f 100644 --- a/works/life/computer-network-experiment/client.cpp +++ b/works/life/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."));
+ }
}
}
|