Programming Perl

Programming PerlSearch this book
Previous: 3.2.3 absChapter 3
Functions
Next: 3.2.5 alarm
 

3.2.4 accept

accept NEWSOCKET, GENERICSOCKET

This function does the same thing as the accept system call - see accept(2). It is used by server processes that wish to accept socket connections from clients. Execution is suspended until a connection is made, at which time the NEWSOCKET filehandle is opened and attached to the newly made connection. The function returns the connected address if the call succeeded, false otherwise (and puts the error code into $!). GENERICSOCKET must be a filehandle already opened via the socket operator and bound to one of the server's network addresses. For example:

unless ($peer = accept NS, S) {
    die "Can't accept a connection: $!\n";
}

See also the example in the section "Sockets" in Chapter 6, Social Engineering.


Previous: 3.2.3 absProgramming PerlNext: 3.2.5 alarm
3.2.3 absBook Index3.2.5 alarm