Network Programming with Perl


 
Network Programming with Perl

By Lincoln  D.  Stein

Slots : 1

Table of Contents
Chapter  18.   The UDP Protocol

    Content

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. The general solution is to use sequence numbers to track requests and their responses. This works quite well but complicates the program.

Alternatively, one might not care about occasional dropped messages. The chat server developed in the next chapters illustrates this principle.


   
Top

Категории