Stackoverflow users!
I have an application that needs to deal with p2p, and this is how I get to UDP Hole punching. But I ran into implementation issues. Hope you can give me some advice.
I have a server that works fine and injects clients into eachother, but the clients cannot connect, probably due to my little experience with sockets. So, the client algorithm:
- Create an udp socket (socket (AF_INET, SOCK_DGRAM, IPPROTO_UDP) )
- Send a message to the server through the sendto function
- Use the recvfrom function to lock to get a response from the server
After these three steps, I get the endpoint with peers. Then I tried to connect clients in two ways:
Way1
- Use the same socket to send peer-to-peer data through the sendto function , but passing another sockaddr
- Listen with the recvfrom locker function (and at that moment I get the message WSAECONNRESET )
Way2
- Create new socket
- Tie him
- Use it to send data to peer
- Listen
Thus, one client fails while binding, and the other fails when listening with WSAEADDRINUSE and WSAECONNRESET errors . I obviously am doing something wrong and your help would be greatly appreciated. Thanks in advance.
P.S. UDP Hole Punching, , : http://www.brynosaurus.com/pub/net/p2pnat/