aboutsummaryrefslogtreecommitdiff
path: root/computer-network-experiment/client.cpp
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2021-06-07 20:20:10 +0800
committercrupest <crupest@outlook.com>2021-06-07 20:20:10 +0800
commitbc0e9b6558b7737846699c41196433055f915aec (patch)
tree6922ae75da4feb22b88d6ed2e247593dfa178a0e /computer-network-experiment/client.cpp
parent1b8ff04e64e054a061f157b9458cf7c73dba43a9 (diff)
downloadlife-bc0e9b6558b7737846699c41196433055f915aec.tar.gz
life-bc0e9b6558b7737846699c41196433055f915aec.tar.bz2
life-bc0e9b6558b7737846699c41196433055f915aec.zip
...
Diffstat (limited to 'computer-network-experiment/client.cpp')
-rw-r--r--computer-network-experiment/client.cpp19
1 files changed, 8 insertions, 11 deletions
diff --git a/computer-network-experiment/client.cpp b/computer-network-experiment/client.cpp
index 922ecdc..2494bae 100644
--- a/computer-network-experiment/client.cpp
+++ b/computer-network-experiment/client.cpp
@@ -37,19 +37,16 @@ int Main() {
PrintErrorMessageAndExit(CRUT("Failed to connect!"));
}
- const int buffer_size = 100;
- char *buffer = new char[buffer_size];
-
- int received_number = recv(client_socket, buffer, buffer_size, 0);
-
- if (received_number == -1) {
- PrintErrorMessageAndExit(CRUT("Failed to recv."));
+ String name;
+ {
+ auto guard = BlockOutputThread();
+ output_stream << CRUT("Please input your name:");
+ name = ReadInputLine();
}
- std::string s(buffer, received_number);
-
- SendOutput(OutputColor::Green, CRUT("Received message:\n"));
- SendOutput(OutputColor::Normal, CRUT("{}\n"), ConvertCharString(s));
+ String name_data = ConvertCharString(name);
+ SafeSend(client_socket,
+ std::string_view{name_data.data(), name_data.size() + 1});
CloseSocket(client_socket);
return 0;