Hello.
I got a little stuck when trying to setup a monitoring system sending all information to the server.
The idea is to use UDP and packets to simplify things, communication is only one-way.
This is what I've come up with so far, the idea is to be able to have a loop at the server side which spits out whatever comes in (cout), and if there is an error display that too.
#include <SFML/Network.hpp>
#include <iostream>
using namespace std;
int main() {
sf::UdpSocket socket;
// bind the socket to a port
if (socket.bind(54000) != sf::Socket::Done) {
cout << "There was an error binding to port 54000." << endl;
}
else {
cout << "UDP socket is listening." << endl;
}
system("pause"); //Please ignore this, windows specific non-recommended stuff.
return 0;
}
And on the client side I just want to send some information.
#include <SFML/Network.hpp>
#include <iostream>
using namespace std;
int main() {
sf::IpAddress recipient = "127.0.0.1";
unsigned short port = 54000;
string message = "Hello";
double speed = 10.3345;
sf::Packet packet;
packet << message << speed;
sf::UdpSocket.send(packet, recipient, port); // This is the line VS 2015 don't like*
system("pause"); //Please ignore this, windows specific non-recommended stuff.
return 0;
}
My coding skills are rather basic, but I'm missing something here.
Thank you for anyone taking their time to help me out.
For the record, I used these pages when trying to set it up.
https://www.sfml-dev.org/tutorials/2.4/network-socket.phphttps://www.sfml-dev.org/tutorials/2.4/network-packet.php