So I tried creating an application using udp sockets. I messed around with it a bit and didn't seem to be able to get it to work.. so I decided to just copy/paste the example code from the class reference.
void main()
{
char ctype;
cin>>ctype;
if (ctype=='c')
{
// ----- The client -----
// Create a socket and bind it to the port 55001
sf::UdpSocket socket;
socket.bind(55001);
// Send a message to 192.168.1.50 on port 55002
std::string message = "Hi, I am " + sf::IpAddress::getLocalAddress().toString();
socket.send(message.c_str(), message.size() + 1, "192.168.1.50", 55002);
// Receive an answer (most likely from 192.168.1.50, but could be anyone else)
char buffer[1024];
std::size_t received = 0;
sf::IpAddress sender;
unsigned short port;
socket.receive(buffer, sizeof(buffer), received, sender, port);
std::cout << sender.toString() << " said: " << buffer << std::endl;
}
else
{
// ----- The server -----
// Create a socket and bind it to the port 55002
sf::UdpSocket socket;
socket.bind(55002);
// Receive a message from anyone
char buffer[1024];
std::size_t received = 0;
sf::IpAddress sender;
unsigned short port;
socket.receive(buffer, sizeof(buffer), received, sender, port);
std::cout << sender.toString() << " said: " << buffer << std::endl;
// Send an answer
std::string message = "Welcome " + sender.toString();
socket.send(message.c_str(), message.size() + 1, sender, port);
}
}
Compiles without errors but when I run the application, nothing happens.
I should probably say that the two computers I'm using are connected to the internet using a wireless router and have the same Public IP.
A solution to this beginners' problem would be appreciated a lot- maybe I'm just missing something really simple..?
Thanks in advance