File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11#include < iostream>
2+ #include < limits>
23#include " ExampleRegistry.h"
34#include " TCPClient.h"
45
@@ -12,15 +13,26 @@ void run() {
1213 std::cout << " connect failed\n " ;
1314 return ;
1415 }
15-
16- client.send (" Hello server\n " );
17-
16+ std::cout << " connected to " << " host: " << client.getHost ()
17+ << " port:" << client.getPort () << " \n " ;
1818 std::string response = client.receive ();
19-
20- std::cout << " server: " << response << std::endl;
19+ std::cout << response << std::endl;
20+ std::string msg;
21+ while (true ) {
22+ if (!std::getline (std::cin, msg)) {
23+ std::cout << " get line failed" << std::endl;
24+ break ;
25+ };
26+
27+ // TODO: why we need \n here
28+ client.send (msg + " \n " );
29+ response = client.receive ();
30+ std::cout << response;
31+ }
2132
2233 client.close ();
2334 } catch (const std::exception& e) {
35+ // Connection closed by foreign host
2436 std::cout << " error: " << e.what () << std::endl;
2537 }
2638}
You can’t perform that action at this time.
0 commit comments