I start the server script up, it prints the server host and port and then waits at the "accept" call. I run the client script, the server script prints the client host and port (which I've removed for brevity) and (apparently) waits for text input from the client.
The client gets and prints the welcome message from the server. I then type text expecting the server to accept it, reverse it, and send it back, but the server script never sees anything at the while ($m = <NEWSOCK>) statement.
The client script is invoked by ./clientScript localhost 7654
Incidentally, I want the server script to eventually run as a daemon on a Solaris server, but first things first.
Thanks very much for any responses, I really do appreciate your attention.
- Dan
#--------------------------------------------------------------------- +---- #SERVER SCRIPT #!/usr/bin/perl -Tw require 5.002; use Socket; #- ReverseEchoer.pl ((c) 1999 Dr. Herong Yang example) $domain = 2; # Internet domain $type = 1; # Sequenced, reliable, two-way connection, byte streams socket(SOCK, PF_INET, SOCK_STREAM, getprotobyname('tcp')); $host = pack('C4', 0, 0, 0, 0); # Local wildcard host id: 0.0.0.0 $port = 7654; $address = pack('S n a4 x8', $domain, $port, $host); bind(SOCK, $address); $queueSize = 5; # Queue up to 5 connections listen(SOCK, $queueSize); $cAddress = accept(NEWSOCK, SOCK); ($cDomain, $cPort, $cHost) = unpack('S n a4 x8', $cAddress); select(NEWSOCK); $| = 1; select(STDOUT); print NEWSOCK "Welcome to Reverse Echo Server.\r\n"; ##### print this +to the client (COMMENT 1) while ($m=<NEWSOCK>) { ##### wait for input from client, but nothing e +ver comes (COMMENT 5) $m =~ s/\n|\r//g; last if ($m eq "."); $m = reverse($m); print NEWSOCK "$m\r\n"; } close(NEWSOCK); #--------------------------------------------------------------------- +---- #CLIENT SCRIPT #!/usr/bin/perl -w require 5.002; use strict; use Socket; my ($remote, $port, $iaddr, $paddr, $proto, $line, $m); $remote = shift || 'localhost'; $port = shift || 7654; if ($port =~ /\D/) { $port = getservbyname($port, 'tcp') } die "No port" unless $port; $iaddr = inet_aton($remote) or die "no host: $remote"; $paddr = sockaddr_in($port, $iaddr); $proto = getprotobyname('tcp'); socket(SOCK, PF_INET, SOCK_STREAM, $proto) or die "socket: $!"; connect(SOCK, $paddr) or die "connect: $!"; while ($line = <SOCK>) { print $line; ##### the Welcome line appears here (COMMENT 2) $m = <STDIN>; ##### I type "abc" here... (COMMENT 3) print SOCK $m; ##### ...send it to the server socket script (COMMENT + 4) } close(SOCK) or die "close: $!";
In reply to Socket Communication-duh by dant
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |