"Out-of-Band" Data and the Urgent Pointer

Remember the send() and recv() calls from Chapter 4 (Other Socket-Related Functions)? We are now going to use them for the first time.

You can send a single byte of TCP urgent data over a connected socket by calling send() with the MSG_OOB flag:

send ($socket,'a',MSG_OOB) or die "Can't send(): $!";

In this code fragment, we call send() to transmit the character "a" across the socket $socket. The MSG_OOB flag specifies that the message is urgent and must be delivered right away. On the other end, the recipient of the message can read the urgent data by calling recv() with the same flag:

recv ($socket,$data,1,MSG_OOB) or die "Can't recv(): $!";

Here we're asking recv() to fetch 1 byte of urgent data ...

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.