Skip navigation

I had this problem that kept coming up again and again, so I’m recording it here.

The problem is when you have a server that listens for UDP packets. Its fine, its open, no firewalls are causing issues at that end. Say its at 200.100.205.70:10006

Now, you want to connect to that server using a UDP sockets program on your local machine. Because you have a firewall, you need to DICTATE from which IP:Port your local sockets program will send sockets.

So naturally, you first go to your firewall software (in your router) and you open port 10007 on 192.168.1.105 (which is your IP address assigned to you by your router).

Now from your client sockets program, you send UDP packets out on a UDP socket which is bound to 127.0.0.1:10007.

It doesn’t work.

WHY??? BECAUSE YOU DIDN’T OPEN 127.0.0.1 ON YOUR ROUTER/FIREWALL, NINNY, YOU OPENED 192.168.1.105!!

Even though the UDP socket is being sent from “THIS MACHINE” (which is probably what you intended when you used the loopback), LOOPBACK != EXTERNAL IP ADDRESS!!

Sending data from the loopback address is actually completely different to the router.. than sending data from your externally assigned ip address. So, yes, if you are connected to the internet, your computer DOES have minimum 2 ip addresses (loopback and the external ip address the router gives you). Actually it has 5: 127.0.0.1, 127.0.0.2, 127.0.0.3, 127.0.0.4 are all loopback. Then the external ip (which for me was 192.168.1.105).

OK!! So how do you fix it?

You bind the UDP socket to

192.168.1.105

OR

bind it to (IPADDRESS.ANY, 10007) (like, 0.0.0.0:10007).

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: