Cool, that seams to work but now another problem appears. i thought i could resolve the problem by sharing an object but it seams i cannot. because in threaded server application it looks like the object shared is type of a globe (
$client == IO::Socket::INET=GLOB(0x189a908)) which is unsharable for now.
#!/usr/bin/perl -w
use strict;
use IO::Socket;
use threads;
use threads::shared;
my $server = IO::Socket::INET->new( Proto => 'tcp',
LocalPort => $ARGV[0],
Listen => SOMAXCONN,
Reuse => 1);
die "can't setup server" unless $server;
share(my @jobs);
while (my $client = $server->accept()) {
$client->autoflush(1);
print "[Connect from ". $client->peerhost . ":" . $client->peerpo
+rt . "]\n" ; # clients address
my $thr = threads->new(sub {
push(@jobs,share($client)); ### NOTE THIS IS UNS
+HARABLE ###
while (<$client>) {
if (/test/i){
print $client "looks good, @jobs\n";
}
elsif (/quit/i){
print $client "bye\n";
last;
}
} # finishe while
}
)->detach;
close $client;
}
since you had the similar problem couple a years ago i was wondering if you found the solution or.... (
sharing globs)
thank you
so the idea is when one client talks server listens and shares its responses with all connected clients
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.