Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: sf::IpAddress::Broadcast returns wrong ip address  (Read 2768 times)

0 Members and 1 Guest are viewing this topic.

antinoid

  • Newbie
  • *
  • Posts: 8
    • View Profile
sf::IpAddress::Broadcast returns wrong ip address
« on: March 29, 2022, 09:02:35 pm »
so I'm making a local multiplayer game that allows a server and client to see each other by broadcasting a UDP message from the server every second with some information, such as the name of the game, IP of the host, number of players, etc. I was using sf::IpAddress::Broadcast but it returns 255.255.255.255 with works on localhost, but other people in the LAN didn't receive any messages.

I read https://serverfault.com/questions/219764/255-255-255-255-vs-192-168-1-255 and so instead of using sf::IpAddress::Broadcast, I changed it to 192.168.1.255, and it works perfectly, I understand that this wouldn't work on all networks as they would have different network addresses, but I'm just wondering why sfml returns an IP that doesn't work on the LAN.

This might be a problem only for me, I'm not sure but any help or information about it would be appreciated.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10815
    • View Profile
    • development blog
    • Email
Re: sf::IpAddress::Broadcast returns wrong ip address
« Reply #1 on: March 30, 2022, 02:39:23 pm »
If you follow the link in the comment of the linked question, you'd find additional links to the RFC specificiations.

Quote from: RFC 919 §7
   The address 255.255.255.255 denotes a broadcast on a local hardware
   network, which must not be forwarded.  This address may be used, for
   example, by hosts that do not know their network number and are
   asking some server for it.

   Thus, a host on net 36, for example, may:

      - broadcast to all of its immediate neighbors by using
        255.255.255.255

      - broadcast to all of net 36 by using 36.255.255.255

   (Note that unless the network has been broken up into subnets, these
   two methods have identical effects.)

255.255.255.255 is the broadcast to ALL on the local network. Whether the broadcast actually happens however depends on your router.
As such, it would seem like your router only allows more specific subnet broadcasts. Check your router if you have an option to change this.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything