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:
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 the server is like this:
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";
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.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.