1
Network / 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;
}
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;
}