I am trying to create a server that will transfer messages from one client to the other. In order to do that I need to keep a list of client sockets. I am using threads::shared, and every time I try to &share() the new clients socket, I get an error message that you cannot share globs yet.
Is there any way around this?
use threads;
use threads::shared;
use IO::Socket;
my $server = new IO::Socket::INET(LocalHost => 'localhost',
LocalPort => 3333,
Proto => 'tcp',
Listen => SOMAXCONN,
Reuse => 1);
my %CLIENTS : shared = ();
my $clientID : shared = 0;
while( my $newClient = $server->accept ) {
$clientID++;
$CLIENTS{$clientID} = &share($newClient); #<--Error
print "hCLIENT: " . $CLIENTS{$clientID} . "\n"
}
I know that POE is an alternative, but I would like to use threads instead.
Thanks, Bill
Code tags added by GrandFather
2006-05-10 Retitled by planetscape, as per Monastery guidelines: one-word (or module-only) titles pose a hazard to site navigation
( keep:0 edit:8 reap:0 )
Original title: 'threads::shared'
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.