This is my server session code that should read the incoming client data asynchronously. I am using a free standing read function. When I tested this using Google Test(using local host, and both client and server on same computer), it worked fine. I was able to connect to server using my test client and server used to establish connection and read the data coming from client.
But when I tested in client and server running on different computers, I observed that after connection is established, Server only receives first of the N data items sent by client. And that too when client disconnects after it has finished writing.
My head is spinning and I am not able to find out why. Any help is much appreciated.
Thanks
void ServerSession::doRead()
{
asio::async_read(socket_, asio::buffer(data_,maxLength),
[this](std::error_code ec, std::size_t length)
{
if(!ec || ec == asio::error::eof)
{
std::string msg{data_, length};
addMessageToQueue(std::move(msg));
}
else
{
socket_.close(); //force close the socket upon read error.
}
});
}