Looping Client and Server Boost ASIO C++

  boost, boost-asio, c++, client, server

I’m trying to write a program that issues a question to the client, then gains a response from the client. The server will check if it’s right or wrong, then it will loop again to ask another question.

So far I’ve gotten the server to do one cycle of this, but when it moves onto the next question the client is unable to input anything else.

Server Code:

boost::asio::io_service ios;
tcp::endpoint end(tcp::v4(), 7000);
tcp::acceptor acc(ios, end);
tcp::iostream stream;
acc.accept(*stream.rdbuf());

for (;;)
{
    s.chooseCategory(r.myMap);
    std::string recv;
    stream >> recv; // recieve data;
    s.checkWord(recv);
    stream << "Thanks" << std::endl;
}

Client Code:

std::cout << "Client" << std::endl;
std::string test;

tcp::iostream stream("127.0.0.1", "7000");
for (;;)
{
    std::cin >> test;
    stream << std::string(test) << std::endl;
    std::string recv;
    std::getline(stream, recv);
    stream >> recv; // output what is recieved
    std::cout << recv << std::endl;
}

I think the concept I have for this works, but won’t work as I would hope it would for networking. Any help or advice would be appreciated.

Source: Windows Questions C++

LEAVE A COMMENT