diff options
author | crupest <crupest@outlook.com> | 2021-06-07 20:20:10 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2021-06-07 20:20:10 +0800 |
commit | bc0e9b6558b7737846699c41196433055f915aec (patch) | |
tree | 6922ae75da4feb22b88d6ed2e247593dfa178a0e /computer-network-experiment/server.cpp | |
parent | 1b8ff04e64e054a061f157b9458cf7c73dba43a9 (diff) | |
download | life-bc0e9b6558b7737846699c41196433055f915aec.tar.gz life-bc0e9b6558b7737846699c41196433055f915aec.tar.bz2 life-bc0e9b6558b7737846699c41196433055f915aec.zip |
...
Diffstat (limited to 'computer-network-experiment/server.cpp')
-rw-r--r-- | computer-network-experiment/server.cpp | 29 |
1 files changed, 4 insertions, 25 deletions
diff --git a/computer-network-experiment/server.cpp b/computer-network-experiment/server.cpp index ac80125..2877c61 100644 --- a/computer-network-experiment/server.cpp +++ b/computer-network-experiment/server.cpp @@ -22,34 +22,13 @@ const u_short port = 1234; // control bind port void ResponseThreadProc(int socket, sockaddr_in address) {
auto address_string = inet_ntoa(address.sin_addr);
- SendOutput(CRUT("Connected to {}!\n"), ConvertCharString(address_string));
- const std::string_view buffer = "Love you!!! By crupest!";
+ std::string rest;
- const int total_byte_count = buffer.size();
- int byte_count_sent = 0;
- int retry_count = 0;
+ std::string name = SafeReadUntil(socket, '\n', rest);
- while (true) {
- // Now we have sent all data.
- if (byte_count_sent == total_byte_count)
- break;
-
- auto byte_actually_sent = send(socket, buffer.data() + byte_count_sent,
- buffer.size() - byte_count_sent, 0);
-
- // send failed
- if (byte_actually_sent == -1) {
- SendOutput(OutputType::Error, CRUT("Failed to send!\n"));
- CloseSocket(socket);
- break;
- }
-
- byte_count_sent += byte_actually_sent;
- }
-
- SendOutput(OutputColor::Green, CRUT("Succeeded to send message to {}!\n"),
- ConvertCharString(address_string));
+ SendOutput(CRUT("Connected to {}, whose name is {}."),
+ ConvertCharString(address_string), ConvertCharString(name));
CloseSocket(socket);
}
|