0

I have been trying to understand the basic idea behind UDP hole punching, and I'm having trouble understanding the difference between the following two socket bindings:

 sock = UDPSocket.new
 sock.bind('', port ) 

and

sock = UDPSocket.new
sock.bind('0.0.0.0', port)

Previously I had thought using '' or '0.0.0.0' did the same thing -- allow the socket to listen on any network interface -- but since the code didn't work with them interchanged I must be missing something.

For the initial 'punch' the datagram is sent from a socket bound to '', which is then closed and the actual communication with the remote host is done over a socket bound to 0.0.0.0. I know 0.0.0.0 generally refers to the default route, but I can't figure out the significance of that in this situation. Does binding a socket to 0.0.0.0 mean you're assigning it the address of the default gateway?

sham
  • 1

1 Answers1

0

Looks like both provides the same behavior: your socket is listening on all interfaces on given port:

ruby      38156 grych    7u  IPv4 0x40a92a845129cab1      0t0  UDP *:6666

My system is Darwin 14.0 (OS X Mavericks), ruby 2.0.0 - I am wondering if it depends on the OS.

Grych
  • 2,861
  • 13
  • 22