Tardis has asked for the wisdom of the Perl Monks concerning the following question:
I am writing a small Perl/TK app, which communicates with other instances of itself on a LAN (think a sort of Instant Messaging application).
This snippet of code works under FreeBSD, but not under Linux:
Running under FreeBSD works (as verified with a tcpdump process), running under Linux gives a:#!/usr/bin/perl -w use IO::Socket; use strict; my($sock, $server_host, $msg, $port, $ipaddr, $hishost, $MAXLEN, $PORTNO, $TIMEOUT); $MAXLEN = 1024; $PORTNO = 5151; $server_host = '192.168.0.255'; $msg = "test"; $sock = IO::Socket::INET->new(Proto => 'udp', PeerPort => $PORTNO, PeerAddr => $server_host) or die "Creating socket: $!\n"; $sock->sockopt(SO_BROADCAST, 1); # $sock->sockopt(SO_DONTROUTE, 1); $sock->send($msg) or die "send: $!";
I was given the two options to set on the socket (via 'sockopt') by a C programmer - the 'SO_DONTROUTE' doesn't seem to be necessary. Turning it on does not make it work under Linux. The 'SO_BROADCAST' is 100% necessary for it to work at all under FreeBSD.Creating socket: Permission denied
Yes, I really want to use UDP broadcasts. Suggestions I use unicast addresses will be cheerfully ignored :-)
Oh, and although it would be totally unsuitable for my application, I did try running it as root. It made no difference.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: UDP broadcast using IO::Socket under Linux
by fokat (Deacon) on Jan 28, 2003 at 05:33 UTC | |
Re: UDP broadcast using IO::Socket under Linux
by Tardis (Pilgrim) on Jan 30, 2003 at 05:22 UTC |