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

I use the Net::Server and this works great, much nicer than my home-brew server. At this moment it has only one problem: for my application I need to know the client's IP-number. I now use:
sub GetIt { my $self = shift; my $prop = $self->{server}; my $addr= $prop->{peeraddr};
but I wonder if this is "the right way"? It looks a bit clumsy.

Thanks a lot, F.

Replies are listed 'Best First'.
Re: IP-number retrieval from Net::Server
by NetWallah (Canon) on Apr 28, 2005 at 03:13 UTC
    Does this look any nicer ? (untested)
    sub GetClientIP { my $self = shift; return $self->get_property('peeraddr'); }

         "There are only two truly infinite things. The universe and stupidity, and I'm not too sure about the universe"- Albert Einstein

Re: IP-number retrieval from Net::Server
by ghenry (Vicar) on Apr 28, 2005 at 09:41 UTC

    What about:

    # for each connection... my $client_addr; while ($client_addr = accept(CLIENT, SERVER)) { # find out who connected my ($client_port, $client_ip) = sockaddr_in($client_addr); my $client_ipnum = inet_ntoa($client_ip); my $client_host = gethostbyaddr($client_ip, AF_INET); # tell who connected print "got a connection from: $client_host", " [$client_ipnum]\n";

    This is taken from: Listing C in the article Build complex GUI applications with Gtk2-Perl

    HTH.

    Walking the road to enlightenment... I found a penguin and a camel on the way.....
    Fancy a yourname@perl.me.uk? Just ask!!!