DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Vortx.pl

02.01.2008
| 1969 views |
  • submit to reddit
        #!/usr/bin/perl -w
# Vortex0.pl
#----------------

use strict;
use Socket;

# initialize host and port
my $host = shift || 'localhost';
my $port = shift || 5842;
my $server = "vortex.labs.pulltheplug.org";

# create the socket, connect to the port
socket(SOCKET,PF_INET,SOCK_STREAM,(getprotobyname('tcp'))[2])
   or die "Can't create a socket $!\n";
connect( SOCKET, pack( 'Sn4x8', AF_INET, $port, $server ))
       or die "Can't connect to port $port! \n";


my $comm;
while($comm=<STDIN>)
{
    chomp $comm;


    if($comm ne '')
    {
	
	print "\n Received 4-Byte Password '", $pass,"'\n";
	$SOCKET->recv($pass,4);

        print "\n Sending message '",$pass,"'";
        if($SOCKET->send($pass))
        {
            print "[Done] CONGRATS! Time for some Vodka","\n";
        }
    }


    else
    {
        # Send an empty message to server and exit
        $SOCKET->send($pass);
        exit 1;
    }
}


close SOCKET or die "close: $!";