#!/usr/bin/perl -w use strict; use IO::Socket; @ARGV == 2 or die "IP:Portnumber Nickname needed "; my ( $host, $port, $kidpid, $handle, $line,$nickname, $connect_check, $nick_che$ ($host, $port)=@ARGV; my $input = $ARGV[0]; $nickname = $ARGV[1]; my @arguments= split(':',$input); my $server_ip= $arguments[0]; my $server_port=$arguments[1]; $handle = IO::Socket::INET->new( Proto => "tcp", PeerAddr => $server_ip, PeerPort => $server_port ) or die "can't connect to port $server_port on $server_ip: $!"; $handle->autoflush(1); print STDERR "[Connected to $host:$port]\n"; $handle->recv($connect_check,255); $nickname= "NICK" . " $nickname"; $handle->send($nickname); $handle->recv($nick_check,255); #die "can't fork: $!" unless defined( $kidpid = fork() ); # the if{} block runs only in the parent process #if ($kidpid) { # copy the socket to standard output # while ( defined( $line = <$handle> ) ) { # print STDOUT $line; # } #kill( "TERM", $kidpid ); # send SIGTERM to child #} # the else{} block runs only in the child process #else { # # copy standard input to the socket # while ( defined( $line = ) ) { # print $handle "$line"; # } #}