I am trying to create a server and client using sf::UdpSocket, when testing locally on the same computer the program worked and sent the messages, however when trying it over the internet with a friend it didn't work, no errors, the message just wasn't received.
I changed the code to use sf::TcpSocket and this time it worked, both locally and over the internet. I definitely port forwarded correctly, as I checked both using this website
http://www.portchecker.net/udp.php, and
http://portforward.com/'s downloadable port checker. Besides this I already have working UDP ports for my teamspeak server, so it's clearly not all UDP traffic.
I googled to see if anyone had this problem but couldn't find anything.
Server Code:
sf::UdpSocket socket;
char buffer[1024];
size_t received = 0;
sf::IpAddress sender;
unsigned short port;
if (socket.bind(2802) != sf::Socket::Done)
{
cout << "Error, couldn't bind udp socket!" << endl;
}
socket.receive(buffer, sizeof(buffer), received, sender, port);
cout << sender.toString() << " said: " << buffer << std::endl;
string message = "Hi, I am " + sf::IpAddress::getLocalAddress().toString();
socket.send(message.c_str(), message.size() + 1, sender, port);
Client Code:
if (socket.bind(sf::Socket::AnyPort) != sf::Socket::Done)
{
cout << "Error, couldn't bind udp socket!" << endl;
}
string message = "Hi, I am " + sf::IpAddress::getLocalAddress().toString();
socket.send(message.c_str(), message.size() + 1, server_ip, server_port);
char buffer[1024];
std::size_t received = 0;
sf::IpAddress sender;
unsigned short port;
socket.receive(buffer, sizeof(buffer), received, sender, port);
cout << sender.toString() << " (The Server) sent back its ip address: " << buffer << endl;