0
我想写一个简单的客户端发布一个UDP消息到服务器。我的缓冲区不是作为udp发送的。当我尝试将消息发送到netcat时,它不会出现。简单的udp客户端提升
#include <iostream>
#include <boost/array.hpp>
#include <boost/asio.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/thread.hpp>
int main(int argc, char *argv[])
{
boost::asio::io_service io_service;
boost::asio::ip::udp::endpoint endpoint_(boost::asio::ip::address::from_string("0.0.0.0"), 2399);
boost::asio::ip::udp::socket socket(io_service, endpoint_);
boost::asio::socket_base::broadcast option(true);
socket.set_option(option);
char* data = "hello";
socket.send_to(boost::asio::buffer(data, strlen(data)), endpoint_);
getchar();
return 0;
}
如果您绑定套接字到ip'0.0.0.0'这意味着,它会听上所有可用的接口。我不知道,如果这与广播一起工作。你可以通过将它绑定到127.0.0.1并尝试广播来开始缩小。如果也失败,请尝试发送到netcat的端点。这样你可以隔离你的问题。 – OutOfBound