----- Original Message ----- From: "mkondelk" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Monday, October 25, 2004 6:39 AM Subject: Interactive socket client
> I have this interactice client: > > #!/usr/bin/perl -w > use strict; > use IO::Socket; > my ($host, $port, $kidpid, $handle, $line); > unless (@ARGV == 2) { die "usage: $0 host port" } > ($host, $port) = @ARGV; > # create a tcp connection to the specified host and port > $handle = IO::Socket::INET->new(Proto => "tcp", > PeerAddr => $host, > PeerPort => $port) > or die "can't connect to port $port on $host: $!"; > $handle->autoflush(1); # so output gets there right away > print STDERR "[Connected to $host:$port]\n"; > # split the program into two processes, identical twins > die "can't fork: $!" unless defined($kidpid = fork()); > # the if{} block runs only in the parent process > if ($kidpid) { > # copy the socket to standard output > while (defined ($line = <$handle>)) { > print STDOUT $line; > } > kill("TERM", $kidpid); # send SIGTERM to child > } > # the else{} block runs only in the child process > else { > # copy standard input to the socket > while (defined ($line = <STDIN>)) { > print $handle $line; > } > } > > on the server run this script: > > #!perl -w > > use IO::Socket; > > $PORT = 7890; > $server = IO::Socket::INET-> new (LocalPort => $PORT,Listen => 5); > > while ($client = $server->accept()) > { > print $client "Command?\r\n"; > $client->autoflush(1); > while ( <$client>) > { > if (/q/) { last; } > elsif (/dfc/) { print $client `dir /-C`."\r\n" ; } > print $client "Command?\r\n"; > } > close $client; > } > > > > why don't work under WinXP? I have ASPerl 5.8. If I connect from telnet, > client works normally. Thanks. I think the problem is that your child dies before your parent reads any data and closes STDIN+OUT. You can see that if you install SIG CHLD handle. Don't forget that parent and child have same file handles, and execution order of process is never a sure thing. The reason why it works on your unix box, is because you are not fighting for time slices with other process's. Don't forget that on Windows it's also not true parent/client environment. If you need more help, don't hesitate to ask again. HTH, M Goland > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > <http://learn.perl.org/> <http://learn.perl.org/first-response> > > > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>