Solved

IO::Socket and IO:Select problem

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Rename file based on contents in the file? 3 97
use google analytics code in perl script 2 81
To run CGI/perl on tomcat and connect to oracle database. 5 135
Perl tar error 8 66
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…
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…
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…

839 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