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

Author Topic: Some general questions about UDP  (Read 2030 times)

0 Members and 1 Guest are viewing this topic.

Doodlemeat

  • Guest
Some general questions about UDP
« 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 :)

Strelok

  • Full Member
  • ***
  • Posts: 139
    • View Profile
    • GitHub
Re: Some general questions about UDP
« Reply #1 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
« Last Edit: July 22, 2014, 03:09:22 am by Strelok »

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Some general questions about UDP
« Reply #2 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
« Last Edit: July 22, 2014, 03:24:37 am by FRex »
Back to C++ gamedev with SFML in May 2023