title: Perl Net::WebSocket::Server
body: <p>I am using the Perl Module Net::WebSocket::Server to build a message deliver system for users that are visiting a domain. I amd using the example scripts from the CPAN module page, and this is the code I have running:</p>
  
  <pre><code>#!/usr/bin/perl
  use strict;
  use warnings;
  use IO::Socket::SSL;
  use Net::WebSocket::Server;
  
  my $ssl_server = IO::Socket::SSL-&gt;new(
        Listen        =&gt; 5,
        LocalPort     =&gt; 4000,
        Proto         =&gt; 'tcp',
        SSL_cert_file =&gt; '/ssl/domain.com.crt',
        SSL_key_file  =&gt; '/ssl/domain.com.key',
      ) or die "failed to listen: $!";
  
  my $port = 4000;
  #print "Starting WebSocket chat server on port $port, press Ctr-C to disconnect\n$
  Net::WebSocket::Server-&gt;new(
      listen =&gt; $ssl_server,
      on_connect =&gt; sub {
          my ($serv, $conn) = @_;
          $conn-&gt;on(
              utf8 =&gt; sub {
                  my ($conn, $msg) = @_;
                  # print "got: $msg\n";
                  print $_-&gt;ip() for( $serv-&gt;connections() );
                  print $_-&gt;port() for( $serv-&gt;connections() );
                  $_-&gt;send_utf8($msg) for( $serv-&gt;connections() );
              },
      );
      },
  )-&gt;start;
  </code></pre>
  
  <p>I would like to extract some type of information that will supply me with the users online, for example IP or connection ID and put them all into an array. You can see my commented attempts grab the conection data and print it using datadumper, but this has only resulted in errors or hashes. Can anyone figure out how to extract IPs or connection IDs and put them into an array so I know howmany unique connections there are?</p>
  
  <p>Solution:</p>
  
  <pre><code>Net::WebSocket::Server-&gt;new(
      listen =&gt; $ssl_server,
      on_connect =&gt; sub {
          my ($serv, $conn) = @_;
  
          $conn-&gt;on(
              utf8 =&gt; sub {
                  my ($conn, $msg) = @_;
                  $IP = $conn-&gt;ip();
                  $PORT = $conn-&gt;port();
                  # print "got: $msg\n";
                  $_-&gt;send_utf8('IP: ' . $IP . ' PORT: ' . $PORT  . ' '. $msg) for( $serv-&gt;connections() );
              },
      );
      },
  )-&gt;start;
  </code></pre>