Following the guidelines I found in numerous examples on the web, I =
wrote a simple Client-Server app in Perl. However, it appears that the =
send buffer does not get flushed until the connection is closed. That's =
fine for one-way data transfer, but I need the server to be able to =
receive some request parameters and then respond to them.
Code fragment illustrating how I'm sending lines of data:
---
use Socket;
$| =3D 1; # force a fflush after every print
my $servername =3D 'localhost';
my $port =3D 8888;
my $proto =3D getprotobyname('tcp');
my $iaddr =3D inet_aton($servername);
my $paddr =3D sockaddr_in($port, $iaddr);
socket(SOCKET, PF_INET, SOCK_STREAM, $proto)
or die "socket: $!";
connect(SOCKET, $paddr) or die "connect: $!";
my $line;
# =
=
# Start off by sending the server a message, terminated by new-line
# =
=
print SOCKET "MAXLENGTH=3D14 MAXWORDS=3D200\n";
#
# Now read the server's reply
# =
while ($line =3D <SOCKET>) {
print "$line";
}
close SOCKET or die "close: $!";
---
(Omitting server code for brevity -- hopefully, my error is evident =
here)
This deadlocks waiting on $line =3D <SOCKET>. Using the debugger on the =
server, I can see that the connection is accepted, but the client's =
initial message is never received.
Any suggestions?
Thanks,
Chap=
--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
