I writing TCP client which should be able to send and receive data at the same time.
Could you tell me how should I call async_send and async_receive is separate threads?
In the other words how to call
m_Socket.async_send(boost::asio::buffer(txBuf.c_str(), txBuf.length()+1),
boost::bind(&TCPClient::sendingHandler, this, boost::asio::placeholders::error));
m_Socket.async_receive(boost::asio::buffer(rxBuf, maxBufLen),
boost::bind(&TCPClient::sendingHandler, this, boost::asio::placeholders::error));
in
boost::thread receivingThread(boost::bind(...));
boost::thread sendingThread(boost::bind(...));
And will it work correctly if I call async_send or async_receive again inside handlers? I need an infinitive loop for sending/receivind data.
Main idea is – send and receive in recursion inside
TCPClient::sendingHandler/receivingHandleron the 2io_service's. Thisio_service'sare called inside 2 threads –This idea is clearly seen in this tutorial. The only difference that you have to call and use 2 separate
io_service's.Another option is 1
io_serviceand multiply threads callingio_service::run. But then you have to useboost::asio::strandfar thread safety: