Reputation: 960
The code below has worked for over a decade and still does on the handful of machines (on a private LAN) running various flavors of linux, that I have it installed on -- until yesterday. Yesterday, I tried it on a freshly installed CentOS 7 machine and although I do not get any errors nothing is ever received. I have also checked the upd sending machine and it is definitely sending to the local IP address of this new machine. Is there something about the network protocalls in CentOS 7 that would prevent UDP packets from being received? I did notice a few things different when setting up the new machine on the lan: ifconfig not there (I installed it), eth0 was called something like enp9so I changed it to eth0 and the /usr/sbin/setup utility does not see my nic in order to allow me to configure it. I was -- I believe -- able to overcome all these obstacles and the machine performs all network functions ping, ssh, ypbind, etc. normally however this mysterious deafness of $sock->recv persists. Does anyone know how I can fix this?
use Socket;
use IO::Socket;
my ($sock, $oldmsg, $newmsg, $MAXLEN); #porto def.
$MAXLEN = 1024;
my $PORTNO = 5151;
my $sock = IO::Socket::INET->new(LocalPort => $PORTNO, Proto => 'udp')
or die "socket: $@";
$oldmsg = "This is the starting message.";
while ($sock->recv($newmsg, $MAXLEN)) {
# do some stuff with the data received.
}
Upvotes: 1
Views: 163
Reputation: 242443
Make sure there's no firewall running that blocks the traffic. If there is, change its configuration to allow your specific packets to get through.
Upvotes: 3