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

Author Topic: [RESOLVED] outgoing UDP Broadcast blocked on one machine  (Read 6401 times)

0 Members and 1 Guest are viewing this topic.

Raincode

  • Full Member
  • ***
  • Posts: 118
    • View Profile
[RESOLVED] outgoing UDP Broadcast blocked on one machine
« on: August 30, 2016, 02:56:51 am »
Hello,

I am trying to write a simple LAN Multiplayer for my Battleship game.

I want to broadcast the IP of the server on the LAN, so any client will automagically find the server.

I wrote this ugly "minimal" example.

Note:
    If I run both client and server on either A or B, I receive the IP.
    If I run server on A and client on B I receive the IP.
    However, if I run the server on B and client on A, I don't receive it.

I have tried various inbound/outbound firewall rules and checked my network visibility settings, or however you may call it (I am running windows machines).

I tried a minimal TCP connection example and it connected properly regardless if I ran server/client on A/B machine. Talk about being confused. I also tried sending directly to the IP, instead of broadcasting - still doesn't work.

I would appreciate it if someone could verify my program is OK, and I have to keep looking for the problem with my setup. Perhaps someone has an idea what might be going on, or what else I could try.

#include <iostream>
#include <SFML/Network.hpp>
#include <SFML/System.hpp>
int main()
{
    std::cout << "run as server (y/n)? ";
    char answer {};
    std::cin >> answer;

    constexpr unsigned short Port {50000};

    int ticks {};
    sf::UdpSocket socket;
    socket.setBlocking(false);
    bool is_server {answer == 'y'};
    if (!is_server)  {
        socket.bind(Port);
    }
    while (ticks < 50) {
        if (is_server) {
            sf::Packet p;
            if (socket.send(p, sf::IpAddress::Broadcast, Port) == sf::Socket::Done) {
                std::cout << "Broadcasted IP\n";
            }
        }
        else {
            sf::Packet p;
            sf::IpAddress remoteAddr;
            unsigned short remotePort;
            if (socket.receive(p, remoteAddr, remotePort) == sf::Socket::Done) {
                std::cout << "Received IP: " << remoteAddr.toString() << '\n';
            }
        }
        ++ticks;
        sf::sleep(sf::seconds(1));
    }

    char ch {};
    std::cin >> ch;
    return 0;
}
 

Kind Regards,
Raincode
« Last Edit: August 30, 2016, 04:51:28 pm by Raincode »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
AW: outgoing UDP Broadcast blocked on one machine
« Reply #1 on: August 30, 2016, 08:54:45 am »
Try to use the subnet's broadcast address (e.g. 192.168.1.255 for 192.168.1.1/24).

When having network trouble it's best to install Wireshark on both machines and see what gets actually sent and received.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Raincode

  • Full Member
  • ***
  • Posts: 118
    • View Profile
Re: outgoing UDP Broadcast blocked on one machine
« Reply #2 on: August 30, 2016, 04:50:07 pm »
Hello eXpl0it3r,

thank you for your reply.

I tried using the "192.168.1.255" Address, with the same result.

I installed wireshark and ran it. I observed that my broadcasts where showing up in "VirtualBox Host Only Network", while the broadcasts coming from the other machine (which I receive) where in "WiFi".

So I disabled that VirtualBox Adapter and the packets started showing up in Wifi:
This is the same place where the packets from the other machine show up, which I can receive.

So to visualize (while broadcasting from both machines):
Machine A (192.168.1.3, Wireless Network Connection):
192.168.1.3     255.255.255.255 UDP     61216 --> 50000
192.168.1.4     255.255.255.255 UDP     53524 --> 50000

Machine B (192.168.1.4, WiFi):
192.168.1.3     255.255.255.255 UDP     61216 --> 50000
192.168.1.4     255.255.255.255 UDP     53524 --> 50000

I verified that I am checking the correct adapters.

Problem is, I still don't see the packets from .4 server on my .3 client. HOWEVER, if I start running a server from .3 while a server is running on .4, I receive both .3 AND .4 packets on my .3 client. But before broadcasting from the same machine, the other packets are ignored for some reason (although wireshark clearly shows them coming in). I also used portqry to check UDP on port 50000 and my client is listening. It is so confusing  to see the packets fly by on wireshark
192.168.1.4     255.255.255.255 UDP     53524 --> 50000
and not get any output on my client.

So I deleted all firewall rules for my application on .3, and just hit "allow access" again after starting it, and voila it works now. <3 windows...

I don't even know if the firewall settings where messed up, or if it was that other adapter anymore, but whatever...

Thank you for the support.

Kind Regards,
Raincode



 

anything