So, I don't know why this isn't working. I've read some documentation and I've made this code. Both server and client are ran on the same machine.
SERVER
///////SERVER
#include <iostream>
#include <SFML/Network.hpp>
#include <string>
using namespace std;
int main()
{
sf::UdpSocket socket;
sf::Packet packet;
sf::Time time;
sf::Clock clock;
int i = 0;
std::string hello = "Hello World!";
packet << hello;
// bind the socket to a port
socket.bind(4000);
sf::IpAddress recipient = sf::IpAddress::getPublicAddress();
unsigned short port = 5400;
while(i == 0)
{
time = clock.getElapsedTime();
if(time.asSeconds() >= 2)
{
std::cout << "Sent to: " << recipient << ":" << port << std::endl;
clock.restart();
socket.send(packet, recipient, port);
}
}
std::cout << "Adress: " << recipient << std::endl;
return 0;
}
CLIENT:
/////////////CLIENT
#include <iostream>
#include <SFML/Network.hpp>
#include <string>
int main()
{
sf::UdpSocket socket;
sf::Packet packet;
sf::IpAddress sender;
unsigned short senderPort, socketPort;
socketPort = 5400;
socket.bind(socketPort);
std::string hello;
std::cout << sf::IpAddress::getPublicAddress() <<":"<< socketPort << std::endl;
socket.receive(packet, sender, senderPort);
packet >> hello;
std::cout << "received: " << hello << std::endl;
}