Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks, I want to have a IO::Socket::Multicast-Server sending its info to some clients or users.
But how can I have this multicast-socket-server normally waiting for its clients to connect?

The example-code is described as: "The following is an example of a multicast server.
Every 10 seconds it transmits the current time and the list of logged-in users to the local network
using multicast group 226.1.1.2, port 2000 (these are chosen arbitrarily)."

But when the users were logging in? Before $sock was created? Ant where and how could they have logged in?

#!/usr/bin/perl # server use strict; use IO::Socket::Multicast; use constant DESTINATION => '226.1.1.2:2000'; my $sock = IO::Socket::Multicast->new(Proto=>'udp',PeerAddr=>DESTINAT +ION); while (1) { my $message = localtime; $message .= "\n" . `who`; $sock->send($message) || die "Couldn't send: $!"; } continue { sleep 10; }
Using google I couldn't even found sample code of others.
I tried s.th like:
while( !$sock->connected ) {sleep 1; }
which dies because "$sock is not defined" ...

My target is a server program that collects data form its own sources (by pipes)
saves them into files and distribute them to several clients (or users) if there are any.

I have had a solution by using normal sockets and threads-shared, but after the threads-module was updated
it now stops as soon as the first client drops its connection.

Your help is highly appreciated, because this is source of my data..
Thanks a lot in advance,
Carl

Replies are listed 'Best First'.
Re: need Socket::Multicast-help
by samtregar (Abbot) on Jun 20, 2007 at 17:48 UTC
    I'm no expert, but I don't think multicast is what you're looking for. IO::Socket::Multicast lets you send and recieve multicast UDP packets. UDP means no connections and multicast means no control over who receives the messages. The docs for the module do a pretty good job explaining this - did you read them?

    -sam

      that is where my code is from and that is from where my questions derive..
        You read the documentation and you're still wondering how you can have your server wait for connections from clients? The docs say:

        These addresses do not correspond to individual machines, but to multicast groups. Messages sent to these addresses will be delivered to a potentially large number of machines that have registered their interest in receiving transmissions on these groups. They work like TV channels. A program tunes in to a multicast group to receive transmissions to it, and tunes out when it no longer wishes to receive the transmissions.

        That's probably the best description of multicast UDP I've read. It's definitely not a client/server system in the usual sense - there's no way a server can wait for connections because there are no connections!

        -sam