3
我很努力接收數據與同步客戶端代碼使用數據報Unix套接字與Boost.Asio。數據報Unix域套接字與Boost.Asio
該服務器似乎工作正常,因爲如果我連接到它與netcat我收到數據。但是,嘗試使用下面的代碼時,它會卡在receive_from()中。 strace顯示receive_from()系統調用被調用,但沒有收到任何內容,而strace在服務器上顯示正嘗試向客戶端發送數據,但未能這樣做。
boost::asio::io_service io_service;
boost::asio::local::datagram_protocol::socket socket(io_service);
socket.open();
cmd::cmd cmd;
cmd.type = cmd::cmdtype::request;
cmd.id = cmd::cmdid::dumptop;
boost::asio::local::datagram_protocol::endpoint receiver_endpoint("socket.unix");
/* The server receives this data successfully */
socket.send_to(
boost::asio::buffer(reinterpret_cast<char*>(&cmd),
sizeof(cmd)),
receiver_endpoint
);
boost::array<char, 128> recv_buf;
boost::asio::local::datagram_protocol::endpoint ep;
/* When the server sends data, nothing is received here.
Maybe it's an issue with the endpoint??? */
size_t len = socket.receive_from(
boost::asio::buffer(recv_buf), ep);
可能值得在客戶端和服務器上發佈strace輸出的相關部分。 – cmeerw
沒有如receive_from()系統調用。你的意思是recv(2)? –