Good day.
I'm trying to implement a question - answer logic using boost::asio.
On the Client I have:
void Send_Message()
{
....
boost::asio::async_write(server_socket, boost::asio::buffer(&Message, sizeof(Message)), boost::bind(&Client::Handle_Write_Message, this, boost::asio::placeholders::error));
....
}
void Handle_Write_Message(const boost::system::error_code& error)
{
....
std::cout << "Message was sent.\n";
....
boost::asio::async_read(server_socket_,boost::asio::buffer(&Message, sizeof(Message)), boost::bind(&Client::Handle_Read_Message, this, boost::asio::placeholders::error));
....
}
void Handle_Read_Message(const boost::system::error_code& error)
{
....
std::cout << "I have a new message.\n";
....
}
And on the Server i have the "same - logic" code:
void Read_Message()
{
....
boost::asio::async_read(client_socket, boost::asio::buffer(&Message, sizeof(Message)), boost::bind(&Server::Handle_Read_Message, this, boost::asio::placeholders::error));
....
}
void Handle_Read_Message(const boost::system::error_code& error)
{
....
std::cout << "I have a new message.\n";
....
boost::asio::async_write(client_socket_,boost::asio::buffer(&Message, sizeof(Message)), boost::bind(&Server::Handle_Write_Message, this, boost::asio::placeholders::error));
....
}
void Handle_Write_Message(const boost::system::error_code& error)
{
....
std::cout << "Message was sent back.\n";
....
}
Message it's just a structure.
And the output on the Client is: Message was sent.
Output on the Server is: I have a new message.
And that's all. After this both programs are still working but nothing happens.
I tried to implement code like:
if (!error)
{
....
}
else
{
// close sockets and etc.
}
But there are no errors in reading or writing. Both programs are just running normally, but doesn't interact with each other.
This code is quite obvious but i can't understand why it's not working.
Thanks in advance for any advice.