boost::asio 和 send() 的使用
使用 boost::asio::ip::tcp:socket
时,可以使用多种方法来写入/发送数据。还有 asio::write 将套接字作为参数等。我的问题是,在使用标准 send()
函数时,boost asio 库是否存在任何兼容性问题(陷阱)?
是否应该绝对不要在 boost::asio::ip::tcp:socket
上使用标准 send()
函数?或者也许它工作得很好,但是当你在 boost::asio 库中已经拥有了这方面可能需要的一切时,为什么还要使用 send()
呢?
When using a boost::asio::ip::tcp:socket
there are many methods one can use to write/send data. There's also asio::write that takes the socket as a parameter, etc. My question is is there any compatibility issues (gotchas) with the boost asio libraries when using the standard send()
function?
Should one categorically never use the standard send()
function on a boost::asio::ip::tcp:socket
? Or maybe it works fine, but why use send()
when you already have everything you could possibly need in this regard within the boost::asio libraries.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于UDP套接字,您需要使用boost asio send和send_to函数,而write方法用于同步流写入,即用于TCP,不能用于UDP,因为它是“流写入”。
You need to use the boost asio send and send_to function for UDP sockets while the write method is used for synchronous stream write i.e used for TCP and cannot be used for UDP as it is "stream write".