#!/usr/bin/perl -w use strict; use IO::Socket; my( $sock, $r_msg, $in_msg, $inhost, $MAXLEN, $PORTNO ); $MAXLEN = 10240; $PORTNO = 7780; $sock = IO::Socket::INET->new( LocalPort => $PORTNO, Proto => 'udp' ) or die "socket: $@"; print "Awaiting UDP messages on port $PORTNO\n"; $r_msg = "Received OK."; while ($sock->recv($in_msg, $MAXLEN)) { my($port, $ipaddr) = sockaddr_in($sock->peername); $inhost = gethostbyaddr($ipaddr, AF_INET); no utf8; print "Client $inhost said $in_msg\n"; # print sprintf("%04x",$in_msg)."\n"; use bytes; print length($in_msg)."\n"; $sock->send($r_msg); } die "recv: $!";