Summary

The UDP protocol is a connectionless, unreliable protocol most suitable for brief, stateless interactions.

A UDP client program creates a UDP socket using socket(), sends messages to the remote host using send(), and receives incoming messages with recv(). A UDP server creates a socket using socket(), assigns it to a prearranged port using bind(), awaits incoming requests using recv(), and sends out responses with send().

Because of UDP's unreliability, messages can be lost, and naively written clients, such as those that call send() and recv() in a rigid loop, will hang while waiting for the reply to a message that was never received. One way to handle this problem is with timeouts, but this introduces problems with duplicate responses. ...

Get Network Programming with Perl now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.