Reputation: 50
i'm using the UDT library to transfer files beetween to computers behind NAT. I already did a hole punching protocol in python and i know how it works. Here, i'm trying to bind an UDT socket to an existing UDP socket.
int udt_holepunching(SOCKET sock, SOCKADDR_IN sin, int size, SOCKADDR_IN peeraddr)
{
UDTSOCKET u;
bool rdv = true;
UDT::setsockopt(u, 0, UDT_RENDEZVOUS, &rdv, sizeof(bool));
UDT::bind(u, sock);
UDT::connect(u, &peeraddr, sizeof(peeraddr));
}
with sock
my existing UDP socket
and peeraddr
the adress of the computer that i want to talk
i have this error :
client.cpp: In function ‘int udt_holepunching(SOCKET, SOCKADDR_IN, int, SOCKADDR_IN)’:
client.cpp:29:20: error: invalid conversion from ‘SOCKET {aka int}’ to ‘const sockaddr*’ [-fpermissive]
UDT::bind(u, sock);
^
client.cpp:29:20: error: too few arguments to function ‘int UDT::bind(UDTSOCKET, const sockaddr*, int)’
In file included from client.cpp:13:0:
../src/udt.h:315:13: note: declared here
UDT_API int bind(UDTSOCKET u, const struct sockaddr* name, int namelen);
It's kind of strange because in the UDT bind documentation, it seems to be possible.
Upvotes: 0
Views: 697
Reputation: 851
The technical answer is hidden in comments above: Use
bind2(udtsocket, udpsocket)
on created UDT/UDP sockets.
Concerning hole punching, this may be done without considering UDP, at all, see UDT Hole Punching Pattern. This also shows valid use of the RENDEVOUS option.
UDT in this scenario requires unique connection, i.e. at one time you either connect to the rendevous server or you are in P2P mode with another node; where this is the only proper way to establish a sequence of several independent P2P connections.
What is not perfect in the referenced ´UDT Hole Punching Pattern´ is, that the UDT socket is bound to a fix parameter address; better is to bind the socket to port 0. The system will allocate a suitable dynamic port, which can be retrieved by getsockname()
and then be re-used in the P2P mode.
Upvotes: 0
Reputation: 409442
The linked to reference shows two overloads. The compiler picks the first one (the tree argument overload) because you pass an UDTSOCKET
as the first argument and have a second argument.
Since the the second argument in the three-argument overload is not a SOCKET
you get the first error. And since you're only passing two arguments to a function expecting three you get the second error.
If you want to bind to a specific address (say the sin
argument you pass to your function) then you need to pass a pointer to that address structure as the second argument, and the size of that structure as the third argument:
UDT::bind(u, (const SOCKADDR*) &sin, sizeof(sin));
If you want to use the second overload, then use it:
UDT::bind(sock);
You can't mix and match as you like, you have to pick one or the other.
Upvotes: 0