in reply to Client/server issues - Server is not receiving information until client closes the connection
use Socket qw( PF_INET SOCK_STREAM inet_aton ); $proto = getprotobyname("tcp"); $iaddr = inet_aton($host) or die "Invalid host : $!\n"; $paddr = sockaddr_in($port,$iaddr); socket(SOCKET,PF_INET,SOCK_STREAM,$proto) or die "socket: $!\n"; connect(SOCKET,$paddr) or die "connect: $!\n"; my $old_fh = select(SOCKET); $|=1; select($old_fh);
can be written as:
use IO::Socket::INET qw( ); my $sock = IO::Socket::INET->new( Proto => 'tcp', PeerAddr => $host, PeerPort => $port, ) or die("Unable to create client socket: $!\n");
The server would be
use IO::Socket::INET qw( ); use Socket qw( SOMAXCONN ); my $server_sock = IO::Socket::INET->new( Proto => 'tcp', LocalPort => $port, ReuseAddr => 1, Listen => SOMAXCONN, ) or die("Unable to create server socket: $!\n");
As an additional bonus, IO::Socket::INET turns on autoflush for the socket, so if kyle is correct, it will also fix your problem.
|
|---|