Perl Networking Functions - Interprocess Communication

by Geethalakshmi 2010-09-17 12:34:32

Perl Networking Functions - Interprocess Communication


accept(NEWSOCKET,GENERICSOCKET)
Does the same thing that the accept system call does. Returns true if it succeeded, false otherwise. See section Interprocess Communication, for an example.
bind(SOCKET,NAME)
Does the same thing that the bind system call does. Returns true if it succeeded, false otherwise. NAME should be a packed address of the proper type for the socket. See section Interprocess Communication, for an example.
connect(SOCKET,NAME)
Does the same thing that the connect system call does. Returns true if it succeeded, false otherwise. NAME should be a packed address of the proper type for the socket. See section Interprocess Communication, for an example.
getpeername(SOCKET)
Returns the packed sockaddr address of other end of the SOCKET connection.

# An internet sockaddr
$sockaddr = 'S n a4 x8';
$hersockaddr = getpeername(S);
($family, $port, $heraddr) = unpack($sockaddr,$hersockaddr);

getsockname(SOCKET)
Returns the packed sockaddr address of this end of the SOCKET connection.

# An internet sockaddr
$sockaddr = 'S n a4 x8';
$mysockaddr = getsockname(S);
($family, $port, $myaddr) = unpack($sockaddr,$mysockaddr);

getsockopt(SOCKET,LEVEL,OPTNAME)
Returns the socket option requested, or undefined if there is an error.

listen(SOCKET,QUEUESIZE)
Does the same thing that the listen system call does. Returns true if it succeeded, false otherwise. See section Interprocess Communication, for an example.

recv(SOCKET,SCALAR,LEN,FLAGS)
Receives a message on a socket. Attempts to receive LENGTH bytes of data into variable SCALAR from the specified SOCKET filehandle. Returns the address of the sender, or the undefined value if there's an error. SCALAR will be grown or shrunk to the length actually read. Takes the same flags as the system call of the same name.

send(SOCKET,MSG,FLAGS,TO)
send(SOCKET,MSG,FLAGS)
Sends a message on a socket. Takes the same flags as the system call of the same name. On unconnected sockets you must specify a destination to send TO. Returns the number of characters sent, or the undefined value if there is an error.

setsockopt(SOCKET,LEVEL,OPTNAME,OPTVAL)
Sets the socket option requested. Returns undefined if there is an error. OPTVAL may be specified as undef if you don't want to pass an argument.
shutdown(SOCKET,HOW)

Shuts down a socket connection in the manner indicated by HOW, which has the same interpretation as in the system call of the same name.
socket(SOCKET,DOMAIN,TYPE,PROTOCOL)

Opens a socket of the specified kind and attaches it to filehandle SOCKET. DOMAIN, TYPE and PROTOCOL are specified the same as for the system call of the same name. You may need to run h2ph on `sys/socket.h' to get the proper values handy in a perl library file. Return true if successful. See section Interprocess Communication, for an example.

socketpair(SOCKET1,SOCKET2,DOMAIN,TYPE,PROTOCOL)
Creates an unnamed pair of sockets in the specified domain, of the specified type. DOMAIN, TYPE and PROTOCOL are specified the same as for the system call of the same name. If unimplemented, yields a fatal error. Return true if successful.

Tagged in:

780
like
0
dislike
0
mail
flag

You must LOGIN to add comments