Socket Problem...
From: Hobbit HK (hobbit_hk_at_hotmail.com)
Date: 11/27/03
- Next message: Bigus: "Packages and returning errors"
- Previous message: Jari Aalto+mail.perl: "Emacs modules for Perl programming"
- Next in thread: Ben Morrow: "Re: Socket Problem..."
- Reply: Ben Morrow: "Re: Socket Problem..."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 27 Nov 2003 04:14:03 -0800
I'm using AtivePerl 5.8 on WinXP and trying to do a script which
listens and writes to the same socket (with fork of course...). Now,
everything works great until I'm trying to write to the socket... The
program just stucks, I think because I'm trying to read and write
simultaneously... If I comment the read part everything goes smooth
(except I can't get msgs :)), here's the code:
use IO::Socket;
$|=1;
($host, $port) = @ARGV;
$port=23 if !$port;
$sock=new IO::Socket::INET->new(PeerAddr=>$host, PeerPort=>$port,
Proto=>'tcp') or die "Can't connect to $host on port $port! $!\n";
$sock->autoflush(1);
print "[Connected to $host on port $port]\n";
die "Can't fork! $!\n" unless defined($kidpid=fork());
if ($kidpid) {
while (sysread($sock, $byte, 1)==1) {
print "$byte";
}
kill 9, $kidpid;
}
else {
while (defined($msg=<STDIN>)) {
print "$msg\n";
}
}
- Next message: Bigus: "Packages and returning errors"
- Previous message: Jari Aalto+mail.perl: "Emacs modules for Perl programming"
- Next in thread: Ben Morrow: "Re: Socket Problem..."
- Reply: Ben Morrow: "Re: Socket Problem..."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|