----- Original Message -----
From: "McMahon, Christopher x66156" <[EMAIL PROTECTED]>
Date: Wednesday, July 2, 2003 12:55 pm
Subject: TCP/IP question
Hello Christopher,
>
> I think I'm missing a concept here...
> I built a very simple TCP/IP server like the one on p. 441 of
> the Camel
> book.
> But my server only ever sees the first message from any given
> client.Subsequent messages to my server are ignored. Does anyone
> know what I have
> to do to get my server to handle more than one message?
>
> #!/usr/bin/perl
> use warnings;
> use strict;
> my ($server, $server_port, $client, $input);
>
> use IO::Socket::INET;
>
> $server_port = 33000;
>
> $server = IO::Socket::INET->new (LocalPort => $server_port,
> Type => SOCK_STREAM,
> Reuse => 1,
> Listen => 10 ) #or SOMAXCONN
> or die "Couldn't be a TCP server on port $server_port:
> $! \n";
>
> while ($client = $server->accept()) {
> my $n = sysread($client,$input,1000);
> print "$input\n" ;
> next; #THIS DOESN'T HELP
> }
you should read your loop carefully, in he while condition you will be accepting
connections, you then read a line from a socket, print it , and go onto accepting your
next connection with out closing the socket. hance your client gets stuck. This calls
for a double loop, one for accepting connections and another for reading the data
something like this:
while ($client = $server->accept()) {
while( sysread($client,$input,1000) ){
print "$input" ;
}
}
HTH,
Mark G
>
> _
> This message and any attachments are intended only for the use of
> the addressee and
> may contain information that is privileged and confidential. If
> the reader of the
> message is not the intended recipient or an authorized
> representative of the
> intended recipient, you are hereby notified that any dissemination
> of this
> communication is strictly prohibited. If you have received this
> communication in
> error, please notify us immediately by e-mail and delete the
> message and any
> attachments from your system.
>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]