in reply to Re^2: sockets and such in Perl
in thread sockets and such in Perl

To specifically choose a socket to write to, you could store the "name" and $sock object in some sort of hash, to keep track of them. Then if you want to only write to name "foo" , you can print to $socks{'foo'}{'socket'}. I used an array for simplicity, but you can loop through hash keys too. One thing you will have to watch out for, when printing only to one client, is getting "out -of-sync" with the other clients. Occasionly I have seen situations when looping through the hash-of-sockets, I need to print to all clients, BUT change what I print. Like print some text to socks{'foo'}, but $socks{'bar'} and $socks{'baz'} will just get a newline, or some NO-OP type of tag. It's just something to watch out for.

If you want a good explanation of how all this works:

select client server

After reading the above links, you will see that the modules IO::Socket and IO::Select take care of alot of the details for you.


I'm not really a human, but I play one on earth. flash japh