• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 412
  • Last Modified:

IO::Socket and IO:Select problem

Hi!
I'm programming a chatserver in perl. Over the same socket different chatters are to receive the output.
Therefore I'm using IO::Socket and IO:Select. But until now I do only have a quite complicated way to send output to a certain chatter
...
my $listen = IO::Socket::INET->new(Proto => 'tcp',
                           LocalPort => 2323,
                           Listen => 1,
                           Reuse => 1) or die $!;
my $select = IO::Select->new($listen);
...
   for $socket ($select->handles) {
      if (($socket->fileno) == 5)   ### in this case only socket-connection
                                      ### with fileno = 5 should receive $outputstuff
           {$socket->send($outputstuff);}
}
...

Is there a command to send data directly to one certain socket-fileno without running a loop over all available socket-connections?
Thanx a lot!
0
kertis
Asked:
kertis
1 Solution
 
b2piCommented:
Simple, brute force solution.  As you're opening sockets, assign a reference to the socket to a hash based on the fileno...

i.e.

my(%FileNos);
.

$FileNos{$socket->fileno} = \$socket;
..


Later, then, you can just do:

$FileNos{5}->send($outputstuff);

0
 
kertisAuthor Commented:
OK, that works just fine. If there's a way to access sockets by fileno directly please feel free to add a comment.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now