use strict; use IO::Socket; #initial variables to work with my server my $host, $port, $request, $proto = 'tcp'; my $connectresponses = 2; #my ftp server responds with 2 lines when you connect. print "What hostname do you want to connect to? "; chomp( $host = ); print "What port do you want to use? "; chomp( $port = ); my $sock = IO::Socket::INET->new( PeerAddr => $host, PeerPort => $port, Proto => $proto ) || die "Failure: $!"; print "Connection to $host on port $port successful!\n"; unless ( $port == 80 ) { for ( $i = 0; $i < $connectresponses; $i++ ) { $_ = <$sock>; print; } } print "Type commands (solely press enter to exit)\n"; &Terminal; close($sock); print "\nConnection to $host on port $port was closed successfully!\n"; exit; #sub to emulate a terminal sub Terminal { while (1) { $request = ""; chomp( $request = ); print $sock "$request\n"; if ( $port == 80 ) { while (<$sock>) { print; } last; } else { unless ($request) { last; } $_ = <$sock>; print; } } }