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
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.