I'm trying to create a simple client/server using IO::Socket, and well, under Linux everything runs just fine. However, my boss, being a... boss, has decided he wants me to write a Win32 client for him (ugh, what a nightmare this is going to be). Anyhow, my first problem with getting my client to work is that fork() doesn't seem to work properly on Win32 with ActivePerl 5.6.1.631 (Latest Build as far as I can tell. It's really bothering me, as everywhere I look everyone says 'fork() works fine in 5.6... etc'. Basically, through sockets, I'm doing a simple 'Client send server data. Server look at data, send response back to client', and they do this until one or the other decides it's time to close the socket. Here's my code for the client which works just great under linux. Any help in rewriting this thing would be greatly greatly appreciated:
#!/usr/bin/perl
use IO::Socket;
# Make our connections
my $ns1 = new IO::Socket::INET (PeerAddr => shell,
PeerPort => 1200,
Proto => 'tcp'
) or die "Couldn't create socket: $!\n"
+;
# Now let's fork the client so we can read and write
my $pid = fork();
$fork_errlvl = 1 unless defined $pid;
# If we weren't able to fork...
die "Error forking client: Reason: $!\n" if $fork_errlvl != 0;
if ($pid) {
write_sock();
waitpid($pid, 0);
} else {
read_sock();
}
sub write_sock {
foreach my $key (@ARGV) {
print $ns1 "$key\n";
sleep(1);
}
close($ns1);
}
sub read_sock {
while (my $line = <$ns1>) {
chomp($line);
print "$line\n";
if ($line eq 'CAIO') {
close($ns1);
}
}
}