Server IP : 213.176.29.180  /  Your IP : 52.14.120.226
Web Server : Apache
System : Linux 213.176.29.180.hostiran.name 4.18.0-553.22.1.el8_10.x86_64 #1 SMP Tue Sep 24 05:16:59 EDT 2024 x86_64
User : webtaragh ( 1001)
PHP Version : 7.4.33
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON
Directory (0755) :  /lib/../share/tk8.6/../doc/bind/../gawk/../teamd/../perl-IO-Socket-IP/examples/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : //lib/../share/tk8.6/../doc/bind/../gawk/../teamd/../perl-IO-Socket-IP/examples/connect.pl
#!/usr/bin/perl

use strict;
use warnings;

use IO::Poll;
use IO::Socket::IP;
use Socket qw( SOCK_STREAM );
use Getopt::Long;

GetOptions(
   'timeout=f' => \my $TIMEOUT,
) or exit 1;

my $host    = shift @ARGV or die "Need HOST\n";
my $service = shift @ARGV or die "Need SERVICE\n";

my $socket = IO::Socket::IP->new(
   PeerHost    => $host,
   PeerService => $service,
   Type        => SOCK_STREAM,
   Timeout     => $TIMEOUT,
) or die "Cannot connect to $host:$service - $@";

printf STDERR "Connected to %s:%s\n", $socket->peerhost_service;

my $poll = IO::Poll->new;

$poll->mask( \*STDIN => POLLIN );
$poll->mask( $socket => POLLIN );

while(1) {
   $poll->poll( undef );

   if( $poll->events( \*STDIN ) ) {
      my $ret = STDIN->sysread( my $buffer, 8192 );
      defined $ret or die "Cannot read STDIN - $!\n";
      $ret or last;
      $socket->syswrite( $buffer );
   }
   if( $poll->events( $socket ) ) {
      my $ret = $socket->sysread( my $buffer, 8192 );
      defined $ret or die "Cannot read socket - $!\n";
      $ret or last;
      STDOUT->syswrite( $buffer );
   }
}