checking for "quit" input from client to close connection

This commit is contained in:
Bob Polis 2020-04-26 16:23:32 +02:00
parent 98d3e88872
commit 376177c760

View File

@ -49,11 +49,18 @@ void test2() {
for (;;) { for (;;) {
sc::io::socketstream client = server.accept(); sc::io::socketstream client = server.accept();
cerr << "connection from " << client.address() << '\n'; cerr << "connection from " << client.address() << '\n';
client << "ready to echo...\n"; client << "ready to echo...\necho> ";
string line; string line;
while (getline(client, line)) { while (getline(client, line)) {
cerr << "received: " << line << '\n'; cerr << "received: " << line << "\n";
client << line << '\n'; if (line == "quit\r") {
client << "bye\n";
client.close();
break;
} else {
client << line << '\n';
}
client << "echo> ";
} }
} }
} }