#server #!/usr/bin/perl -w # udpqotd - UDP message server use strict; use IO::Socket; my($sock, $newmsg, $hishost, $MAXLEN, $PORTNO); $MAXLEN = 1024; $PORTNO = 5151; $sock = IO::Socket::INET->new( LocalPort => $PORTNO, Proto => 'udp') or die "socket: $@"; print "Awaiting UDP messages on port $PORTNO\n"; while ($sock->recv($newmsg, $MAXLEN)) { my($port, $ipaddr) = sockaddr_in($sock->peername); $hishost = gethostbyaddr($ipaddr, AF_INET); print "Client $hishost said $newmsg\n"; $sock->send("CONFIRMED: $newmsg "); } die "recv: $!"; # You can't use the telnet program to talk to this server. You # have to use a dedicated client.