Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Client send packets to server when on LAN, but not over internet  (Read 3770 times)

0 Members and 1 Guest are viewing this topic.

KingPenguinator

  • Newbie
  • *
  • Posts: 21
    • View Profile
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);
       }
}

 

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: Client send packets to server when on LAN, but not over internet
« Reply #1 on: July 13, 2014, 06:14:47 pm »
Maybe I'm missing something, but it looks like your server code never initializes "port".

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Client send packets to server when on LAN, but not over internet
« Reply #2 on: July 13, 2014, 06:24:18 pm »
It's an output, the receive function defines it.
Laurent Gomila - SFML developer

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: Client send packets to server when on LAN, but not over internet
« Reply #3 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
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

KingPenguinator

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Client send packets to server when on LAN, but not over internet
« Reply #4 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

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: Client send packets to server when on LAN, but not over internet
« Reply #5 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.
« Last Edit: July 14, 2014, 01:17:13 am by zsbzsb »
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: Client send packets to server when on LAN, but not over internet
« Reply #6 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.
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

KingPenguinator

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Client send packets to server when on LAN, but not over internet
« Reply #7 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

 

anything