1
Network / Client send packets to server when on LAN, but not over internet
« on: July 13, 2014, 05:54:13 pm »
Hey, I saw post smiliar to this one, but it was a bit old, I didn't know if should ask there, or create a new one, so I just created a new one. I've seen the FAQ in the other post, i've tried the suggestions that I could do, but to no avail.
Anyway as the title suggests I can talk to the server when I use my local ip, but when I use my external Ip, or ask a friend to try on his pc it looks like it sends the packet, but the server doesn't receive it.
Client :
Server :
Anyway as the title suggests I can talk to the server when I use my local ip, but when I use my external Ip, or ask a friend to try on his pc it looks like it sends the packet, but the server doesn't receive it.
Client :
string id;
cout << "name: ";
cin >> id;
string ip;
cout << "Ip: ";
cin >> ip;
sf::IpAddress sender(ip) ;
sf::UdpSocket socket;
socket.setBlocking(false);
unsigned short port;
cout << "Port: ";
cin >> port;
socket.bind(port+1);
sf::Packet packet;
sf::Packet sendPacket;
sendPacket << "connection" << id;
socket.send(sendPacket, sender, port);
string connected;
socket.receive(packet, sender, port);
if(packet >> connected)
if(connected=="done") //Connection made
//do stuff
cout << "name: ";
cin >> id;
string ip;
cout << "Ip: ";
cin >> ip;
sf::IpAddress sender(ip) ;
sf::UdpSocket socket;
socket.setBlocking(false);
unsigned short port;
cout << "Port: ";
cin >> port;
socket.bind(port+1);
sf::Packet packet;
sf::Packet sendPacket;
sendPacket << "connection" << id;
socket.send(sendPacket, sender, port);
string connected;
socket.receive(packet, sender, port);
if(packet >> connected)
if(connected=="done") //Connection made
//do stuff
Server :
sf::IpAddress sender;
unsigned short port;
socket.receive(packet, sender, port);
if(packet >> commandId)
{
sf::Packet sendPacket;
cout << commandId << endl;
if(commandId=="connection")
{
string idStr;
packet >> idStr;
cout << idStr << " on " << sender.toString().c_str() << " has connected" << endl;
//Do stuff
sendPacket << "done";
socket.send(sendPacket, sender, port);
}
}
unsigned short port;
socket.receive(packet, sender, port);
if(packet >> commandId)
{
sf::Packet sendPacket;
cout << commandId << endl;
if(commandId=="connection")
{
string idStr;
packet >> idStr;
cout << idStr << " on " << sender.toString().c_str() << " has connected" << endl;
//Do stuff
sendPacket << "done";
socket.send(sendPacket, sender, port);
}
}