aboutsummaryrefslogtreecommitdiff
path: root/works/life/computer-network-experiment/server.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
commitc10e08c3896343cc7ddffe1dd7b1d09da2f8548e (patch)
tree9a62f500d177a4190a4c3b642a58a38e109e56ea /works/life/computer-network-experiment/server.cpp
parent04bc88aca6157dfd1d2309b353d9feb64bcc8800 (diff)
downloadcrupest-c10e08c3896343cc7ddffe1dd7b1d09da2f8548e.tar.gz
crupest-c10e08c3896343cc7ddffe1dd7b1d09da2f8548e.tar.bz2
crupest-c10e08c3896343cc7ddffe1dd7b1d09da2f8548e.zip
import(life): ...
Diffstat (limited to 'works/life/computer-network-experiment/server.cpp')
-rw-r--r--works/life/computer-network-experiment/server.cpp29
1 files changed, 4 insertions, 25 deletions
diff --git a/works/life/computer-network-experiment/server.cpp b/works/life/computer-network-experiment/server.cpp
index ac80125..2877c61 100644
--- a/works/life/computer-network-experiment/server.cpp
+++ b/works/life/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);
}