SFML community forums

Help => Network => Topic started by: Doodlemeat on July 22, 2014, 02:30:48 am

Title: Some general questions about UDP
Post by: Doodlemeat on July 22, 2014, 02:30:48 am
Since a UDP socket can receive packets in both blocking and non-blocking, can the socket "loose" packets if the receive function isn't called at the exact same as the packet is received? Could packets be lost when sending from server->client?

Or is the packets stacked in a list somewhere so that I could pop one every server update cycle?

I will start by making simple packet transaction between a client and a server, but I've heard that you should avoid UDP socket because they are not reliable(?). This is the first time for me with networking so I would appreciate any answer :)
Title: Re: Some general questions about UDP
Post by: Strelok on July 22, 2014, 03:02:58 am
Your system has a buffer for the sockets to read. While UDP is better for real time operations the protocol lacks several features that you need in most cases.
Google TCP vs UDP and blocking vs non blocking socket, the gurus at stack overflow will drown you in information :D
Title: Re: Some general questions about UDP
Post by: FRex on July 22, 2014, 03:20:16 am
No, the packet loss has nothing to do with forgetting to call receive, OS will buffer the packets and wait for you to handle them but the buffer that OS has is limited.
Yes, server -> client and client -> server can both lose packets. Also UDP knows nothing of 'server' and 'client' so neither sending direction is special in any way.
You should probably receive all you can from socket as soon as you can.
Also, packets can arrive out of order or duplicated too.
UDP isn't reliable but people get away with it with 'tricks' that make it kind of reliable (in the sense that all data gets transported to the other end, not in the sense that all packets get there - this is impossible).
You might want to read this too:
https://github.com/SFML/SFML/wiki/FAQ#should-i-use-tcp-or-udp-sockets