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
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.