On Thu, Jul 24, 2003 at 01:22:50PM +0200, Gooly wrote:
> Hi,
> 
> it's the first time that I've used POE (based on its chat-server) to realize a 
> Socket-based program that sends from a 'studio' to all listening clients the 
> same data (lines).
> 
> That works so far,
> but now I'd like the server to know which ip-addr are allowed to conntect and 
> which are to reject.
> 
> Please give me a hint how can I get th IP-Addr. of the connecting client in 
> this function (of the chat-server):
> 
> sub client_connected {
>     my $session_id = $_[SESSION]->ID;
>     $users{$session_id} = 1;
>     broadcast( \%studio, $session_id, "1 Client connected." );
> }

Using POE::Component::Server::TCP, the remote address (the client's
address) exists as a dotted quad (IPv4) or that thingy with all the
colons in it (IPv6) in $_[HEAP]->{remote_ip}.  The remote port number is
in $_[HEAP]->{remote_port}.

So:

sub client_connected {
  my $remote_ip = $_[HEAP]->{remote_ip};
  my $session_id = $_[SESSION]->ID;
  $users{$session_id} = 1;
  broadcast( \%studio, $session_id, "1 Client connected from $remote_ip." );
}

Other things are provided in Server::TCP sessions' heaps.  See the end
of the SYNOPSIS in perldoc POE::Component::Server::TCP.

-- 
Rocco Caputo - [EMAIL PROTECTED] - http://poe.perl.org/

Reply via email to