몇 시간 동안 문제가 있습니다. 부스트 asio udo 소켓을 엔드 포인트에 연결하고 싶습니다. IPv4에서이 작업을 수행하는 데 아무런 문제가 없습니다. 그러나 IPv6에서 동일한 작업을 수행하려고하면 "잘못된 인수"라는 오류 코드가 표시됩니다.boost asio udp socket connect (IPv6)에 잘못된 인수가 있습니다.
using boost::asio::ip::udp;
struct UdpConnectionParams
{
udp::endpoint m_localEndpoint;
udp::endpoint m_remoteEndpoint;
}
boost::system::error_code setupUdpConnection(udp::socket& p_socket, const UdpConnectionParams& p_params)
{
// close socket
boost::system::error_code h_ignoreError;
p_socket.close(h_ignoreError);
// variables for kind of UDP connection
udp h_protocol(udp::v4());
bool h_shallBind{false};
bool h_shallConnect{false};
// determine kind of connection
if(p_params.m_localEndpoint != udp::endpoint())
{
h_protocol = p_params.m_localEndpoint.protocol();
h_shallBind = true;
}
if(p_params.m_remoteEndpoint != udp::endpoint())
{
h_protocol = p_params.m_remoteEndpoint.protocol();
h_shallConnect = true;
}
if(!h_shallBind && !h_shallConnect)
{
// no endpoint specified, return error
return boost::system::error_code(ENetworkErrorCode::NO_ENDPOINT_SPECIFIED, NetworkErrorCategory::getCategory());
}
try
{
p_socket.open(h_protocol);
//bind socket to certain endpoint
if(h_shallBind)
{
p_socket.bind(p_params.m_localEndpoint);
}
//connect socket to client. Thus it is possible to use p_socket.send()
if(h_shallConnect)
{
p_socket.connect(p_params.m_remoteEndpoint);
}
}
catch (boost::system::system_error& h_error)
{
p_socket.close(h_ignoreError);
return h_error.code();
}
// no error
return boost::system::error_code();
}
int main()
{
boost::asio::io_service service;
udp::socket socket(service);
boost::system::error_code error;
UdpConnectionParams params;
params.m_localEndpoint = udp::endpoint(udp::v6(), 55555);
params.m_remoteEndpoint = udp::endpoint(boost::asio::ip::address_v6::from_string("ff01::101"), 55555);
error = setupUdpConnection(socket, params);
cout << error << error.message() << endl; // "invalid argument"
return 0;
}
오류가 발생하는 유일한 방법은 로컬 호스트 IP 주소 (:: 1)입니다. 소켓을 끝점에 바인딩해도 아무런 차이가 없습니다. 내가 뭘 잘못하고 있니?
고맙습니다! 음, "ff01 :: 101 % eth0"또는 "ff01 :: 101 % lo"로는 작동하지 않지만 "ff12 :: 1 % eth0"와 작동합니다. 노드 로컬 IPv6 멀티 캐스트 그룹에 소켓을 연결하려면 무엇이 필요합니까? 소켓을 연결하지 않고 대신 "send_to"및 "receive_from"메서드를 사용하면이 문제가 발생하지 않습니까? – Christi258
ff11 :: 1 % eth0 (또는 ff11 :: 11 % lo 등)이 노드 로컬 해당 그룹입니다. send_to() 및 receive_from()에서는 작동하지만 connect()에서는 작동하지 않는 이유는 알 수 없습니다. –