mje has asked for the wisdom of the Perl Monks concerning the following question:
I'm stuck with some code which creates a UDP datagram socket and broadcasts a message, a server process picks up the broadcast and attempts to send a reply but the client which sent the broadcast does not see it. Any ideas?
The client is something like this:
and the server is like this:my $socket = IO::Socket::INET->new( Broadcast => 1, Blocking => 1, ReuseAddr => 1, Type => SOCK_DGRAM, Proto => 'udp', PeerPort => 9999, LocalPort => 0, PeerAddr => inet_ntoa(INADDR_BROADCAST)) || confess "error: failed to create broadcast udp socket - $!"; $socket->send('Q', 0); my ($srcaddr, $data); $srcaddr = $socket->recv($data, 100, 0); die "recv: $!" if !defined($srcaddr); close $socket;
and my server outputs: Client xxx.yyy.local/47917 said Q but the client just hangs and receives nothing. This is Linux if it makes any difference and perl 5.8.8.my $socket = IO::Socket::INET->new( Proto => 'udp', Type => SOCK_DGRAM, LocalPort => 9999) || confess "error: failed to create broadcast udp socket - $!"; # server now does select etc to wait for msg my $ip = $socket->recv(my $data, 100); my ($port, $ipaddr) = sockaddr_in($socket->peername); my $hishost = gethostbyaddr($ipaddr, AF_INET); print "Client $hishost/$port said $data\n"; print "sent " . $scoket->send('Refresh', 0, $ip) . "\n";
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: How to answer a UDP broadcast
by Trizor (Pilgrim) on Jun 19, 2007 at 19:32 UTC | |
by mje (Curate) on Jun 19, 2007 at 19:50 UTC | |
by Trizor (Pilgrim) on Jun 19, 2007 at 20:41 UTC | |
by mje (Curate) on Jun 19, 2007 at 21:13 UTC | |
by Trizor (Pilgrim) on Jun 19, 2007 at 22:56 UTC | |
by eric256 (Parson) on Jun 20, 2007 at 00:11 UTC | |
by idsfa (Vicar) on Jun 20, 2007 at 14:40 UTC | |
by mje (Curate) on Jun 21, 2007 at 10:13 UTC | |
Re: How to answer a UDP broadcast
by ikegami (Patriarch) on Jun 19, 2007 at 20:23 UTC | |
by mje (Curate) on Jun 19, 2007 at 21:04 UTC | |
Re: How to answer a UDP broadcast
by mje (Curate) on Jun 20, 2007 at 10:12 UTC |
Back to
Seekers of Perl Wisdom