Solved

IO::Socket and IO:Select problem

Posted on 1998-08-11
2
393 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

947 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

23 Experts available now in Live!

Get 1:1 Help Now