Good way to send/receive UDP packets?

wjoe invalid at example.com
Tue Jul 21 13:05:21 UTC 2020


On Sunday, 19 July 2020 at 09:48:24 UTC, notna wrote:
> Someone once wrote about a UDP library, which was used to sync 
> data to somewhere in APAC (Hongkong?) and by doing so the data 
> transfer was magnitudes faster then before (over TCP)...
>

In the best case scenario, and orders of magnitude more 
unreliable otherwise.

Choosing UDP over TCP because speed is like choosing a hammer 
over a screwdriver to drive in a screw because it works and is 
faster. But it's still the wrong tool for the job.

UDP is a protocol for broadcasting messages which means it's 
connection less, unreliable (as in no guarantees for delivery of 
datagrams or that they'll be delivered only once, order i.e. 
datagrams sent in order A B C D can be delivered like e.g B C A 
D), and data integrity.
It's insecure (as in everyone who listens can receive it).

Once you need any of these features/guarantees you'll lose 
performance just as you would by using TCP, plus you pay the cost 
for re-inventing the wheel, bugs, testing, maintenance, support 
and all.

UDP is the protocol of choice when you want to broadcast, the 
data you send isn't important or the TCP overhead is bigger than 
the transmitted message. Like broadcasting radio/podcasts, 
weather updates for your status bar or some such or DNS queries.

If you need reliable transmission you need to use a reliable 
protocol.


More information about the Digitalmars-d-learn mailing list