UDP broadcast: one computer receives, other doesn't

Started by
2 comments, last by dphoenix 15 years, 6 months ago
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?
Advertisement
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!
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).
enum Bool { True, False, FileNotFound };
Thanks again, hplus. I really appreciate your help!

This topic is closed to new replies.

Advertisement