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

Author Topic: Problems with packets #2.  (Read 3104 times)

0 Members and 1 Guest are viewing this topic.

kapesu8

  • Newbie
  • *
  • Posts: 32
    • View Profile
    • Email
Problems with packets #2.
« on: July 09, 2012, 01:12:02 pm »
I've switched my game to use udp instead of tcp, because you know :P

So I'm testing it over local network and I've faced some problems..

So if we would have a code

sf::UdpSocket socket;
sf::IpAddress SenderAddress;
sf::Packet ReceivedPacket;
unsigned short Port;
if(socket.receive(ReceivedPacket,SenderAddress,Port)==sf::Socket::Done) {
sf::IpAddress SenderLocalAddress = SenderAddress.getLocalAddress();
}

Now would the SenderLocalAddress be the sender's local address or the local host's local address?
Since when I send directly data from the client to server over local network the server receives the data, however when the server tries to response the client doesn't get the data.

And I was just wondering that does it even send it to the right IP?


Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Problems with packets #2.
« Reply #1 on: July 09, 2012, 01:43:13 pm »
SenderAddress.getLocalAddress() doesn't make sense. getLocalAddress() is a static function of IpAddress which returns your own local IP address. SenderAddress is the address of the sender.
Laurent Gomila - SFML developer

kapesu8

  • Newbie
  • *
  • Posts: 32
    • View Profile
    • Email
Re: Problems with packets #2.
« Reply #2 on: July 09, 2012, 01:59:25 pm »
So senderaddress is the sender's local address already?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Problems with packets #2.
« Reply #3 on: July 09, 2012, 02:03:10 pm »
Yes.
Laurent Gomila - SFML developer

kapesu8

  • Newbie
  • *
  • Posts: 32
    • View Profile
    • Email
Re: Problems with packets #2.
« Reply #4 on: July 09, 2012, 02:07:51 pm »
To get the sender's global address would I need to include it to the packet from client-side?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Problems with packets #2.
« Reply #5 on: July 09, 2012, 04:00:06 pm »
To be clear: the address that you get is the one that you must use to respond to the sender. You don't need to do anything.
Laurent Gomila - SFML developer