SFML community forums

Help => Network => Topic started by: kapesu8 on July 09, 2012, 01:12:02 pm

Title: Problems with packets #2.
Post by: kapesu8 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?

Title: Re: Problems with packets #2.
Post by: Laurent 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.
Title: Re: Problems with packets #2.
Post by: kapesu8 on July 09, 2012, 01:59:25 pm
So senderaddress is the sender's local address already?
Title: Re: Problems with packets #2.
Post by: Laurent on July 09, 2012, 02:03:10 pm
Yes.
Title: Re: Problems with packets #2.
Post by: kapesu8 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?
Title: Re: Problems with packets #2.
Post by: Laurent 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.