C ++:boost :: asio:write()不支持UDP套接字吗?(C++: does boost::asio:write() not support UDP sockets?)

编程入门 行业动态 更新时间:2024-10-26 19:26:24
C ++:boost :: asio:write()不支持UDP套接字吗?(C++: does boost::asio:write() not support UDP sockets?)

尝试使用boost::asio::write()写入boost::asio::ip::udp::socket对象。 虽然我正忙着重新阅读文档,看看我是否在某个地方出错了,有人可以确认一下是否支持这个吗? 我现在想的是boost::asio::write()只支持tcp::socket对象,而不支持udp::socket 。

这是我尝试编译时得到的:

/usr/include/boost/asio/impl/write.ipp: In function ‘size_t boost::asio::write(SyncWriteStream&, const ConstBufferSequence&, [...cut...] test/test.cpp:76: instantiated from here /usr/include/boost/asio/impl/write.ipp:44: error: ‘class boost::asio::basic_datagram_socket<boost::asio::ip::udp, boost::asio::datagram_socket_service<boost::asio::ip::udp> >’ has no member named ‘write_some’

我想我在文档中读到这个时决定尝试使用boost::asio::write() :

发送操作可能不会将所有数据发送到对等方。 如果需要确保在阻塞操作完成之前写入所有数据,请考虑使用write函数

...但是回过头来看,我看到文本只在boost::asio::ip::tcp::socket::send() ,而不在UDP版本中。 资源。

Trying to use boost::asio::write() to write to a boost::asio::ip::udp::socket object. While I'm busy re-reading the docs to see if I've gone wrong somewhere, can someone confirm if maybe this is not supported? I'm now thinking boost::asio::write() only supports tcp::socket objects, not udp::socket.

This is what I get when I try to compile:

/usr/include/boost/asio/impl/write.ipp: In function ‘size_t boost::asio::write(SyncWriteStream&, const ConstBufferSequence&, [...cut...] test/test.cpp:76: instantiated from here /usr/include/boost/asio/impl/write.ipp:44: error: ‘class boost::asio::basic_datagram_socket<boost::asio::ip::udp, boost::asio::datagram_socket_service<boost::asio::ip::udp> >’ has no member named ‘write_some’

I think I decided to try boost::asio::write() when I read this in the docs:

The send operation may not transmit all of the data to the peer. Consider using the write function if you need to ensure that all data is written before the blocking operation completes.`

...but in going back, I see that text is only in boost::asio::ip::tcp::socket::send() and not in the UDP version. Source.

最满意答案

假设您需要同步行为,则需要使用boost::asio::ip::udp::socket类的send或send_to成员方法。 boost::asio::write free函数使用SyncWriteStream类型要求,UDP套接字不符合要求。

Assuming you want synchronous behavior, you need to use the send or send_to member methods of the boost::asio::ip::udp::socket class. The boost::asio::write free function uses the SyncWriteStream type requirement, which a UDP socket does not meet.

更多推荐

本文发布于:2023-07-09 00:16:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1082131.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不支持   write   asio   boost   support

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!