Marv Brafman writes:
> I'm trying to create a simple client/server where the
> client sends one line of text to the server and the
> server displays the text. The client and server are
> running on the same NT 4.0 machine. Everything seems
> to work, except that the length of the text recieved
> by the server is NULL. This happens whether the client
> uses print or syswrite. The code is below. Any hints
> as to what could be wrong? I get the same behavior if
> I telnet to the server.
>
> Client:
>
> use strict;
>
> use IO::Socket;
>
> my ($host, $port, $handle);
>
> unless (@ARGV == 2) { die "usage: $0 host port" }
>
> ($host, $port) = @ARGV;
>
> # create a tcp connection to the specified host
> and port
>
> $handle = new IO::Socket::INET(Proto => "tcp",
>
> PeerAddr =>
> $host,
>
> PeerPort =>
> $port)
>
> or die "can't connect to port $port on
> $host: $!";
>
> # $handle->autoflush(1); # so output
> gets there right away
>
> print STDERR "[Connected to $host:$port]\n";
>
> # print $handle "Hello there !\n";
> syswrite($handle, "Hello there !\n", length("Hello
> there !\n"));
> close ($handle);
>
>
>
> server:
>
> use IO::Socket;
> my $sock = new IO::Socket::INET (
> LocalPort => '1234',
> Proto => 'tcp',
> Listen => 1,
> Reuse => 1,
> );
> die "Could not create socket: $!\n" unless $sock;
> my $new_sock = $sock->accept();
> while(defined(<$new_sock>)) {
Your use of 'defined' here effectively throws the input away. Change
this line to:
while(<$new_sock>) {
Then you can go back to using print in your client.
> print $_, length($_);
> }
> close($sock);
>
> __________________________________________________
> Do You Yahoo!?
> Get email at your own domain with Yahoo! Mail.
> http://personal.mail.yahoo.com/?.refer=text
> _______________________________________________
> ActivePerl mailing list
> [EMAIL PROTECTED]
> http://listserv.ActiveState.com/mailman/listinfo/activeperl
>
--
Brian Raven
My arthritic pinkies are already starting to ache just thinking about ||||=.
-- Larry Wall in <[EMAIL PROTECTED]>
_______________________________________________
ActivePerl mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/activeperl