SFML community forums

Help => Network => Topic started by: KingPenguinator on July 13, 2014, 05:54:13 pm

Title: Client send packets to server when on LAN, but not over internet
Post by: KingPenguinator 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 :
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
 

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);
       }
}

 
Title: Re: Client send packets to server when on LAN, but not over internet
Post by: Ixrec on July 13, 2014, 06:14:47 pm
Maybe I'm missing something, but it looks like your server code never initializes "port".
Title: Re: Client send packets to server when on LAN, but not over internet
Post by: Laurent on July 13, 2014, 06:24:18 pm
It's an output, the receive function defines it.
Title: Re: Client send packets to server when on LAN, but not over internet
Post by: zsbzsb on July 13, 2014, 11:07:38 pm
Quote
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.

https://github.com/SFML/SFML/wiki/FAQ#network-internet-network
Title: Re: Client send packets to server when on LAN, but not over internet
Post by: KingPenguinator on July 14, 2014, 01:10:55 am
I've seen the FAQ in the other post, i've tried the suggestions that I could do, but to no avail.

I've tried the FAQ
Title: Re: Client send packets to server when on LAN, but not over internet
Post by: zsbzsb on July 14, 2014, 01:15:18 am
What else do you want us to say then? Most likely you are behind at least a double layer NAT and there is no way to accept incoming connections without getting a static IP.
Title: Re: Client send packets to server when on LAN, but not over internet
Post by: binary1248 on July 14, 2014, 01:38:47 am
You know... SFML isn't a replacement for the operating system or your networking hardware... If data does not arrive at the destination computer, SFML, no matter how good it is, can't help you. It's that simple.

The fact that you are using UDP for communication doesn't make it any better. Since it is connectionless, the data will always leave the source computer but it is not guaranteed to arrive the destination computer. So saying something like "it looks like it sends the packet" does not help in solving the problem.

Have you verified that the data actually arrives at the destination computer when sent over the internet? You can use many tools for this, Wireshark... netcat... If it doesn't arrive, then this forum is not the right one to seek help in. Everything that people here will tell you is listed in that FAQ. If you need more help than that, there are probably better more specialized forums to ask in than this one.
Title: Re: Client send packets to server when on LAN, but not over internet
Post by: KingPenguinator on July 14, 2014, 11:54:39 am
Okey, i'll see what I can find elsewhere, i'll post back if I find a solution.
As always thanks for the help