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

Author Topic: Broadcast Linux-Window  (Read 2055 times)

0 Members and 1 Guest are viewing this topic.

Shuvi22

  • Newbie
  • *
  • Posts: 6
    • View Profile
Broadcast Linux-Window
« on: August 18, 2023, 05:38:11 pm »
I have a small network code (receiving data to linux, sending data to windows) that sends some information either to a specific local IP or to a broadcastcast. And if the first method works, then the second one only works if Windows receiving data and Linux sending data(linux receives absolutely nothing).

Some information:
SFML 2.6.0
Communication works in both side via tcp

Client(on Windows)
#include <SFML/Network.hpp>
#include <iostream>
#include <string>

int main() {
    sf::UdpSocket socket;
    socket.bind(sf::Socket::AnyPort);
    unsigned short port = 6885;

    std::string data = "Hello, Server";
    //socket.send(data.c_str(), data.size() + 1, sf::IpAddress::IpAddress("192.168.100.148"), port); //It work
    socket.send(data.c_str(), data.size() + 1, sf::IpAddress::Broadcast, port); //It not work, sf::IpAddress::Broadcast is a 255.255.255.255 on both PC


    return 0;
}



Server(on Linux)
#include <SFML/Network.hpp>
#include <iostream>
#include <string>

int main() {
    sf::UdpSocket socket;
    socket.bind(6885);
    std::cout << sf::IpAddress::getLocalAddress() << std::endl;

    char data[128];
    std::size_t received;
    sf::IpAddress remote;
    unsigned short port;
    socket.receive(data, 128, received, remote, port); //Work only if sent to a this IP
    std::cout << data[0];
   

    return 0;
}

 

anything