Thanks mattk
In fact I am using fork() on Windows (my bad). However, my problem reduces to something like this:
My server:
use IO::Socket;
use IO::Select;
my $socket= new IO::Socket::INET (
LocalHost => 'localhost',
LocalPort => 9000,
Proto => 'tcp',
Listen => SOMAXCONN,
Reuse => 1);
if (not defined $socket) {
die "no server";
}
my $sel= IO::Select->new($socket);
print "Waiting for connections on port 9000\n";
my @ready;
my $client;
my $message;
my $new;
while (@ready= $sel->can_read) {
foreach $client (@ready) { #client speaking
if ($client == $socket) { #new client -> add client
print "new client\n";
my $add= $client->accept;
$sel->add($add);
print "added\n";
} else { #old client
print "old client \n";
$client->recv($message,256);
print $client."\n";
$client->send($client);
$client->recv($new, 256);
print $new."\n";
$new->send("ok");
}
}
}
My client:
my $sock;
my $message;
my $socket= new IO::Socket::INET (
PeerHost => 'localhost',
PeerPort => 9000,
Proto => 'tcp');
if (not defined $socket) {
die "no server";
}
$socket->send("something");
$socket->recv($sock, 256);
$socket->send($sock);
$socket->recv($message, 256);
And this gives me something like:
Waiting for connections on port 9000
new client
added
old client
IO::Socket::INET=GLOB(0x1b19628)
IO::Socket::INET=GLOB(0x1b19628)
Can't locate object method "send" via package
"IO::Socket::INET=GLOB(0x1b19628)" (perhaps you forgot to load "IO:Socket::INET=GLOB(0x1b19628)"?) at server.pl line 39
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.