如何在Boost中的Receive之前执行Send执行

时间:2014-10-28 17:15:20

标签: visual-c++

注意:我使用的是Microsoft Visual C ++ 2010 Express。

正如标题所描述的那样,我遇到了Socket.send和Socket.receive的问题。 Socket.receive一直希望在socket执行send之前执行:

    using boost::asio::ip::tcp;
    boost::asio::io_service io_service;
    boost::system::error_code closesock;
    tcp::resolver resolver(io_service);
    tcp::resolver::query query("127.0.0.1", "11113");
    tcp::resolver::iterator endpoint_iterator = resolver.resolve(query);
    tcp::socket socket(io_service);
    boost::asio::connect(socket, endpoint_iterator);
    boost::asio::streambuf recvbuf;
    boost::asio::streambuf::mutable_buffers_type recvbuff = recvbuf.prepare(256);
    const char* sndbuf = "this is the buffer";
    string sendbuff = sndbuf;
    socket.send(boost::asio::buffer(sendbuff)); //This should execute first and finish first
    socket.receive(boost::asio::buffer(recvbuff)); //This should execute second and finish second

所以基本上,这个函数在发送之前一直等待接收。 我希望它首先发送,然后在发送完成后接收。

PS:很抱歉,如果这是重复的,但我到处寻找解决这个问题。

无论如何,早上好:)

0 个答案:

没有答案