This section provides a tutorial example on how to use the Socket.pm module to creating sockets and establish network communication connections.
In the previous examples, there are a lots hard coded values, like socket domain and
socket type. The Socket Module is designed to help you to hide those values. It also
offers a number of methods to pack and unpack IP addresses and socket addresses.
PF_INET - Returns the socket domain number of Internet domain.
SOCK_STREAM - Returns the socket type number for sequenced, reliable, two-way connection, byte streams
INADDR_ANY - Returns the packed wildcard IP address, similar to pack('C4', 0,0,0,0).
inet_aton("216.109.118.67") - Returns the packed form of the specified IP address, similar to
pack('C4', 216,109,118,67). inet_aton("www.yahoo.com") works too.
inet_aton($pHost) - Returns the unpacked form of the specified packed IP address.
pack_sockaddr_in($port, $pHost) - Returns the packed socket address of the specified port number
and packed IP address. Internet domain number will be automatically added. This function is
similar to pack('S n a4 x8', $domain, $port, $pHost);
unpack_sockaddr_in($address) - Returns port name and packed IP address in an array
of the specified packed socket address.
sockaddr_in($port, $pHost) - Same as pack_sockaddr_in($port, $pHost) in scalar context.
sockaddr_in($address) - Same as unpack_sockaddr_in($address) in list context.
I revised the Reverse Echoer server application with the help of Socket Module: