#!/usr/bin/perl -w # !!! Server !!! use strict; use IO::Socket; my($sock, $oldmsg, $newmsg, $hisaddr, $hishost, $MAXLEN, $PORTNO); $MAXLEN = 1024; my $sock1 = IO::Socket::INET->new( LocalPort => 6543, Type => SOCK_DGRAM, Proto => 'udp' ) or die "socket: $@"; $oldmsg = "This is the starting message."; while ($sock->recv($newmsg, $MAXLEN)) { my($port, $ipaddr) = sockaddr_in($sock->peername); printf("%s\n",$sock->sockhost); printf("%s\n",$sock->peerhost); $hishost = gethostbyaddr($ipaddr, AF_INET); print "Client $hishost said ``$newmsg''\n"; $sock->send($oldmsg); $oldmsg = "[$hishost] $newmsg"; }