anelson has asked for the wisdom of the Perl Monks concerning the following question:
CLIENT:
use Socket qw(:DEFAULT :crlf); use IO::Handle; my ($remote, $iaddr, $paddr, $proto, $line, $response); $remote = $client || 'localhost'; $port = $port || 8086; # random port if ($port =~ m/\D/) { $port = getservbyname($port, 'tcp') } die "Bad port" unless $port; $iaddr = inet_aton($remote) or die "can't connect: $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: $!"; SOCK->autoflush(1); print SOCK $encrypted_message . CRLF;
SERVER:
and so on . . I can't seem to reliably detect the end of the message. Any advice would be greatly appreciated.use Socket qw(:DEFAULT :crlf); use IO::Handle; next unless my $rem_addr = accept(SESSION,SOCK); my ($r_port,$r_addr) = sockaddr_in($rem_addr); warn "Connection from [", inet_ntoa($r_addr),",$r_port]\n"; SESSION->autoflush(1); my $incoming = ''; my $line = ''; while( defined($line = <SESSION>)) { $incoming .= $line; last if $incoming =~ /\n$/; # vain attempt to find end of line } chomp $incoming; my $msg = decrypt($key, $incoming);
-anelson
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Socket IO problems
by pg (Canon) on Nov 23, 2002 at 05:12 UTC | |
|
Re: Socket IO problems
by dpuu (Chaplain) on Nov 23, 2002 at 05:09 UTC | |
|
Re: Socket IO problems
by anelson (Acolyte) on Nov 23, 2002 at 06:12 UTC |