Generated: Tue Feb 2 17:54:58 2010 from testsock1.pl 2005/03/13 1.5 KB.
#!/usr/bin/perl -w # PeerPort = > "daytime(13)", use IO::Socket; $remote = IO::Socket::INET->new( Proto => "tcp", PeerAddr => "localhost", PeerPort => 8008 ) or die "cannot connect to daytime port at localhost"; while ( <$remote> ) { print } if( 0 ) { #!/usr/bin/perl -w use strict; use Socket; print("Hello World! - I CONNECT ...\n"); my ($remote,$port, $iaddr, $paddr, $proto, $line); $remote = shift || 'localhost'; $port = shift || 8008; # random port if ($port =~ /\D/) { $port = getservbyname($port, 'tcp') } die "No port" unless $port; $iaddr = inet_aton($remote) || die "no host: $remote"; $paddr = sockaddr_in($port, $iaddr); $proto = getprotobyname('tcp'); socket(SOCK, PF_INET, SOCK_STREAM, $proto) || die "socket: $!"; connect(SOCK, $paddr) || die "connect: $!"; while (defined($line = <SOCK>)) { print $line; } close (SOCK) || die "close: $!"; exit; } if( 0 ) { #use IO::Socket; # use IO::Select; # Create a socket to server # my $sock = IO::Socket::INET->new( PeerPort => 8008, Reuse => 1 ) or die "Can't bind : $@\n"; print "Bound to : $sock\n"; print "Writing to connection on port 8008\n"; # print $sock "Hi there ...\n"; $sock->send( "Hi there ...\n" ); $sock->close(); }