c++ - bind existing socket with UDT -
c++ - bind existing socket with UDT -
i'm using udt library transfer files beetween computers behind nat. did hole punching protocol in python , know how works. here, i'm trying bind udt socket 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
existing udp socket , peeraddr
adress of computer want talk
i have error :
client.cpp: in function ‘int udt_holepunching(socket, sockaddr_in, int, sockaddr_in)’: client.cpp:29:20: error: invalid conversion ‘socket {aka int}’ ‘const sockaddr*’ [-fpermissive] udt::bind(u, sock); ^ client.cpp:29:20: error: few arguments function ‘int udt::bind(udtsocket, const sockaddr*, int)’ in file included 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 unusual because in udt bind documentation, seems possible.
the linked reference shows 2 overloads. compiler picks first 1 (the tree argument overload) because pass udtsocket
first argument and have sec argument.
since the sec argument in three-argument overload not socket
first error. , since you're passing 2 arguments function expecting 3 sec error.
if want bind specific address (say sin
argument pass function) need pass pointer address construction sec argument, , size of construction 3rd argument:
udt::bind(u, (const sockaddr*) &sin, sizeof(sin));
if want utilize sec overload, utilize it:
udt::bind(sock);
you can't mix , match like, have pick 1 or other.
c++ sockets udp udt
Comments
Post a Comment