Perl programming on mMPE/iX - August 2001
HP World Page 29August 21, 2001
sockets - a procedural client example
#!/PERL/PUB/perl -w
use Socket;
$proto = getprotobyname('tcp'); # get protocol number
$ipaddr = inet_aton('localhost'); # get the host's IP address
$port = getservbyname('daytime', 'tcp'); # get port number
$address = sockaddr_in($port, $ipaddr); # create addr struct
socket(SOCK, PF_INET, SOCK_STREAM, $proto); # create the socket
connect(SOCK, $address); # connect to remote host
$timestamp = <SOCK>; # read a line of data
print "$timestamp\n"; # print the results
close(SOCK); # close the socket