void waitAndGet(ConnectionHandler &connectionHandler) { while (true) { const short bufsize = 1024; char buf[bufsize]; cin.getline(buf, bufsize); string line(buf); if (!connectionHandler.sendLine(line) || shouldClose) { std::cout << "Disconnected. Exiting...\n" << std::endl; shouldClose = true; connectionHandler.close(); break; } } }
void waitAndListen(ConnectionHandler &connectionHandler) { while (true) { string answer; int len; if (!connectionHandler.getLine(answer)) { std::cout << "Disconnected. Exiting...\n" << std::endl; break; } len=answer.length(); answer.resize(len-1); cout << answer << std::endl << std::endl; if (answer == "SYSMSG QUIT ACCEPTED" || shouldClose) { shouldClose = true; connectionHandler.close(); std::cout << "Exiting...\n" << std::endl; break; } } }
void *ListenInput() { while (running) { std::string answer; int len; if (!connectionHandler.getLine(answer)) { std::cout << "Disconnected. Exiting...\n" << std::endl; running = false; break; } len=answer.length(); // A C string must end with a 0 char delimiter. When we filled the answer buffer from the socket // we filled up to the \n char - we must make sure now that a 0 char is also present. So we truncate last character. answer.resize(len-1); std::cout << answer << " " << std::endl << std::endl; } connectionHandler.close(); return NULL; }