camel book example- clien/server
Hi Folks;
I was trying to hack the client and server examples from the camel book into
a utility I was working on, and ran into a bit of a snag. The code in the
book doesn't quite match the code from the oriely site. Both seem to work,
is there a reason they are different? Also, would anybody care to give me
a pointer on how to get the server to talk to the client? (text sez the client
will echo what the server sends, but as coded the server doesn't send anything:)
Thx,
M2 - oh, btw- replies to this via mail might bounce (sick sendmail daemon);
Here's the code in the client script that's different:
<<from book>>
for($con = 1; ; $con++) {
printf("Listening for connection %d....\n",$con);
($addr = accept(NS,S)) || die $!;
if (($child = fork()) == 0) {
print "accept ok\n";
($af,$port,$inetaddr) = unpack($sockaddr,$addr);
while (<NS>) {
print "$con: $_";
}
close(NS);
exit;
}
close(NS);
Quote:
}
<<From site>>
$con = 0;
print "Listening for connection 1....\n";
for(;;) {
($addr = accept(NS,S)) || die $!;
$con++;
if (($child[$con] = fork()) == 0) {
print "accept ok\n";
($af,$port,$inetaddr) = unpack($sockaddr,$addr);
while (<NS>) {
print "$con: $_";
}
close(NS);
exit;
}
close(NS);
printf("Listening for connection %d\n",$con+1);
Quote:
}