(SRam) wrote in message news:<. com>...
> Subject: creating Handles
I do not think that your question is about creating handles.
> I am coding for a server. After server is reading a particluar port,
> How can I create handles for them and distinguish them individually
I do not understand the question - the code you have written seems to
do just that.
I suspect you were wanting to asking was how to store application
level information assocuated with a socket so that you can retrieve it
when IO::Select passed you a ready handle.
If you use a Perl object reference (other than an object that uses
overload) in a string context it will return a string that can be
assumed to uniquely define that object so long as the object exists.
You can therefore use object references as hash keys.
my $new = $listen->accept;
$socket_info{$new}{FOO} = 'bar';
You need to remember to delete the entry in %socket_info when you
destroy the IO::Socket object.
Alternatively, objects that are based on GLOBS (such as IO::Socket
objects) have spare storage capacity. You can exploit this. The HASH
knob is already used by IO::*, but you can hang private data off the
SCALAR knob.
my $new = $listen->accept;
${*$new}->{FOO}='bar';
You could also use an ARRAY keyed on fileno but this would be
pathologically bad if you ever used a platform where sockets are given
high filenos.
This newsgroup does not exist (see FAQ). Please do not start threads
here.