stackoverflow users!
I have an app that has to deal with p2p, and that's how I get to UDP Hole punching. But I ran into troubles with implementation. Hope, you can give me some tips.
I've got server, which works perfect and introduces clients to eachother, but clients can't connect probably because of my small exp working with sockets. So, client algo is:
- Create udp socket (socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);)
- Send message to server via sendto function
- Use recvfrom locker function to get an answer from server
After those 3 steps I get peer endpoint. Next, I was trying to connect clients in two ways:
Way1:
- Use the same socket to send data to peer via sendto function, but passing another sockaddr
- Listen with recvfrom locker function (And at that point I'm getting WSAECONNRESET error)
Way2:
- Create new socket
- Bind it
- Use it to send data to peer
- Listen
In that way one client fails on binding and another fails on listening with errors WSAEADDRINUSE and WSAECONNRESET. I'm obviously doing something wrong and your help would be highly appreciated. Thanks in advance.
P.S. Wanna share a good article about UDP Hole Punching in order to help those, who is new to this technique: http://www.brynosaurus.com/pub/net/p2pnat/