我有客户端服务器应用程序,流程如下解释:的boost ::通过串行通道ASIO :: ASYNC_WRITE问题
客户端是在窗户边,不使用升压 服务器是在Linux端,并使用升压客户 - 服务器通过串行通道RS485进行通信。并且服务器使用boost::asio::async_write
。
client --> calls command with specific command_id --> server
client <-- sends acknowledgement <-- server
{server process the command, meanwhile the client is blocked for response}
client <-- sends response <-- server
有时会发生什么情况客户端会收到确认,但没有收到即使响应由服务器发送的响应。 当客户端发送另一个命令时,客户端稍后收到待处理的响应。
如果我使用boost::asio::write
进行串行通信,根本没有问题。下面
是ASYNC_WRITE
boost::asio::async_write(serial_port, boost::asio::buffer(&v_chunk[0], v_chunk.size()),
boost::bind(&Serial_channel::async_write_callback, this, boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred));
io_serv->run();
io_serv->reset();
在“服务器”端,您正在正确运行“io_service”事件循环? –
是@Joachim我正确使用了io_service循环。在async_write之后,我使用了io_service.run()和reset()。 –
@Chirag德赛为什么'重置'?你能显示代码吗?很可能,'io_service'失去工作。 –