#!/usr/local/bin/perl5 -w use IO::Socket; #*********************************** # daytime-server.pl - daytime server #*********************************** $port = 8000; # # create a TCP listening socket file descriptor # # LocalPort: list on port $port # Type : use TCP # Resuse : reuse address right away # Listen : buffer at most 10 requests $listenfd = IO::Socket::INET->new(LocalPort => $port, Type => SOCK_STREAM, Reuse => 1, Listen => 10) or die "Couldn't listen on port $port: $@\n"; # # loop forever, waiting for client requests # while(1) { # wait for a connection request and # get the associated connected socket file descriptor $connfd = $listenfd->accept(); # return todays date to the client $time = "The time is ".`date`; $connfd->print($time); # close the socket and its connection close $connfd; }