I have changed my server solution to use perl 5.8 threads, instead of fork. It is set up for non-blocking sockets. It has a client that is non-blocking as well.
my problem is that It still prints to STDOUT, not $client.
Your help is appreciated. Thanks in advance.
Regards,
Jeremy Aiyaduria.
below is the code. ---------------------------------------------------------------------------------------------------------- use IO::Socket; use IPC::Open2; use threads;
#$| = 1;
my $PORT = 8887; # pick something not in use my $server; my $kidpid; my $SDIR = getcwd(); print "$SDIR";
serverproc();
sub serverproc {
$server = IO::Socket::INET->new( Proto => 'tcp', LocalPort => $PORT, Listen => SOMAXCONN, Reuse => 1);
die "can't setup server" unless $server; print "[Server $0 accepting clients]\n"; #while(1) #{
while ($client = $server->accept()) { #$client->autoflush(1); $hostinfo = gethostbyaddr($client,$client->peeraddr); my $cmd = <$client>; open(RH,"|$cmd|"); my $inT = threads->create(\&input,RH,$client); my $outT = threads->create(\&input,RH,$client); } }
sub input($$) { ($WRITEHANDLE,$client) = @_; my $byte; while (defined(my $byte = <$client>)) { print $WRITEHANDLE $byte; }
}
sub output($$)
{
($READHANDLE,$client) = @_;
my $l;
while ((defined ($l = <$READHANDLE>))) {
$client->send($l); <-- data not sent to $client, it is sent to STDOUT , dont know why???????
}
}
Jeremy A wrote:
> Hi all,
>
> I am using IPC::Open2. I have a Read Handle (RH) and a Write Handle (WH). I
> fork() for doing non-blocking IO.
> my problem is , when i try the print the RH to socket ($client), It writes
> to STDOUT (server console screen). nothing gets written to the socket.
>
> Thanks in advance for any help on this.
>
> Regards,
>
> Jeremy Aiyadurai.
>
> The following is the code.
> ----------------------------------------------------------------------------------------
>
> $server = IO::Socket::INET->new( Proto => 'tcp',
> LocalPort => $PORT,
> Listen => SOMAXCONN,
> Reuse => 1);
>
>
> die "can't setup server" unless $server;
> print "[Server $0 accepting clients]\n";
> #while(1)
> #{
>
> while ($client = $server->accept()) {
> $client->autoflush(1);
> my $LFLAG = 0;
> my $UP;
> $hostinfo = gethostbyaddr($client,$client->peeraddr);
> my $cmd = <$client>;
> open2(\*RH,\*WH,"$cmd");
open2 \*WH, \*RH, $cmd;
> die "can't fork: $!" unless defined($kidpid = fork());
There could be problems with forking on Win32.
> if ($kidpid) {
> my $byte;
> while (defined(my $byte = <$client>)) {
> print WH $byte;
> }
> #kill("TERM", $kidpid);
> }
> else {
> my $l;
> while ((defined ($l = <RH>))) { <- problem here, RH does not write
> to client, it writes to STDOUT.
> print $client $l;
> }
>
> }
> }
--
,-/- __ _ _ $Bill Luebkert Mailto:[EMAIL PROTECTED]
(_/ / ) // // DBE Collectibles Mailto:[EMAIL PROTECTED]
/ ) /--< o // // Castle of Medieval Myth & Magic http://www.todbe.com/
-/-' /___/_<_</_</_ http://dbecoll.tripod.com/ (My Perl/Lakers stuff)
_______________________________________________ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
_______________________________________________ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs