Solved

IO::Socket and IO:Select problem

Posted on 1998-08-11
2
389 Views
Last Modified: 2008-03-10
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
Comment
Question by:kertis
2 Comments
 
LVL 5

Accepted Solution

by:
b2pi earned 50 total points
ID: 1209202
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
 

Author Comment

by:kertis
ID: 1209203
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now