Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: reading from multicast socket

by rasta (Hermit)
on Nov 12, 2002 at 08:56 UTC ( [id://212225]=note: print w/replies, xml ) Need Help??


in reply to reading from multicast socket

There are a few mistakes in your code:

1. You should specify local port and SO_BROADCAST flag
2. Use $@ to output error message from new()
3. recv returns the addres of sender

So, here is my code:
my $sock1 = IO::Socket::INET->new( LocalPort => 9897, PeerAddr => inet_ntoa(INADDR_BROADCAST), # you may use '127.0.0.1 +' for local host Proto => 'udp', LocalAddr => '127.0.0.1', Broadcast => 1 ); die "Can't bind to $udpcon: $@\n" unless $sock1; my $data; my $addr; print "waiting for data on $udpcon ...\n"; while (1) { $addr = recv($sock1, $data, 10, 0); }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://212225]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (5)
As of 2024-04-25 12:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found