I've been wanting to experiment with the SFML Network module. Unfortunately I'm running into some issues. I setup the Project with the Visual Studio guide on the SFML website. Everything worked fine, the green circle rendered and the standard "SFML works!" text got printed in the console. I followed the first networking guide step by step and ran into this issue.
Any help is greatly appreciated!
Both applications have the exact same issue so I believe that I setup something incorrectly. I checked if I had linked the .dll files and placed them in the correct directory and found no issues.
This is the Client application:
#include <SFML/Graphics.hpp>
#include <SFML/Network.hpp>
#include <iostream>
int main()
{
sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
sf::CircleShape shape(100.f);
shape.setFillColor(sf::Color::Green);
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
window.draw(shape);
window.display();
}
sf::UdpSocket socket;
if (socket.bind(54000) != sf::Socket::Done)
{
std::cout << "Could not bind socket on port 54000";
}
char data[100] = "test";
sf::IpAddress recipient = "127.0.0.1";
unsigned short port = 54000;
if (socket.send(data, 100, recipient, port) != sf::Socket::Done)
{
std::cout << "Failed to send data";
}
return 0;
}
This is the server application:
#include <SFML/Graphics.hpp>
#include <SFML/Network.hpp>
#include <iostream>
int main()
{
sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
sf::CircleShape shape(100.f);
shape.setFillColor(sf::Color::Green);
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
window.draw(shape);
window.display();
}
sf::UdpSocket socket;
if (socket.bind(54000) != sf::Socket::Done)
{
std::cout << "Could not bind socket on port 54000!";
}
char data[100];
std::size_t received;
//UDP socket
sf::IpAddress sender;
unsigned short port;
if (socket.receive(data, 100, received, sender, port) != sf::Socket::Done)
{
std::cout << "Failed to receive data!";
}
std::cout << "Received " << received << " bytes from " << sender << " on port " << port << std::endl;
return 0;
}
EDIT: literally seconds after posting this I discovered that I had linked all .DLL files except the network one, oops!