server:
#include <SFML/Network.hpp>
#include <iostream>
int main()
{
const unsigned short Port = 2435;
sf::SocketUDP Server;
if (!Server.Bind(Port))
{
std::cout << " error" << std::endl;
}
sf::Packet Packet;
sf::IPAddress ClientAddress;
unsigned short ClientPort;
Server.Receive(Packet, ClientAddress, ClientPort);
int a;
Packet >> a;
std::cout << "packet : " << a << " from "<< ClientAddress <<" port: "<< ClientPort << std::endl;
a=12345;
Packet.Clear();
Packet << a;
Server.Send(Packet, ClientAddress, ClientPort);
std::cin.ignore(10000, '\n');
Server.Close();
return EXIT_SUCCESS;
}
client:
#include <SFML/Network.hpp>
#include <iostream>
int main()
{
const unsigned short Port = 2400;
sf::SocketUDP Client;
if (!Client.Bind(Port))
{
std::cout << " error" << std::endl;
}
sf::Packet Packet;
sf::IPAddress ServerAddress="127.0.0.1";
unsigned short ServerPort=2435;
int a;
a=54321;
Packet << a;
Client.Send(Packet, ServerAddress, ServerPort);
Packet.Clear();
Client.Receive(Packet, ServerAddress, ServerPort);
Packet >> a;
std::cout << "packet : " << a << " from "<< ServerAddress <<" port: "<< ServerPort << std::endl;
std::cin.ignore(10000, '\n');
Client.Close();
return EXIT_SUCCESS;
}
this will do?