Jump to content
  • Advertisement
Sign in to follow this  
dphoenix

UDP broadcast: one computer receives, other doesn't

This topic is 3704 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
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!

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!