Sign in to follow this  
dphoenix

UDP broadcast: one computer receives, other doesn't

Recommended Posts

Good morning all, I have a program that receives and sends UDP broadcasts. I am testing on two Vista computers hooked up to an ethernet hub. I set Laptop A to listen for a UDP broadcast, then have Laptop B broadcast a message. A successfully receives and prints the message. But when I switch the roles and have A broadcasting and B listening, B doesn't receive anything. Firewalls are all off. And also, TCP communication works both ways on the two computers; it's just the UDP that chokes. The computers can ping each other just fine, too. Any idea what I might be doing wrong here?

Share this post


Link to post
Share on other sites
Aha! The laptop that didn't receive the message doesn't have internet access, and the other one does! So when the internet-connected laptop was broadcasting, it sent the broadcast to my wireless internet, not my LAN. When I disabled the internet, the UDP transmission worked on both laptops.

So, problem solved.

But, is there anyway to specify which network I broadcast to? It would be nice if I didn't have to keep switching off the internet to play the game I'm writing. Thanks!

Share this post


Link to post
Share on other sites
Quote:
But, is there anyway to specify which network I broadcast to?


The way it's supposed to work is that if you broadcast on 255.255.255.255, you broadcast to all local subnets. That may or may not be the actual behavior on your laptop.

To broadcast on a specific subnet, find the netmask of that subnet (for example, 10.0.0.0/8 or 192.168.1.0/24) and set all the bits that are not part of the subnet mask (10.255.255.255 or 192.168.1.255) and broadcast on that address. Note that the class A/B/C masking doesn't necessarily work, because users are likely to do further submasking (as in the case of the 192 example above).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this