Creating an Instant Messaging System using PERL – Guide
Recently, while relatively bored i decided to create an instant messaging system running on Ubuntu using PERL. Below is the code, it may be interesting for some people! Basically, V-Recieve is the server which can recieve the messages being sent from all the clients running V-Send. In the program before, i have modified it slightly, so along with printing out the message it runs the command on the system
So messages like “ls -la” will produce an output on the console of the server running V-Recieve, etc. To set this up:
1. Download V-Recieve onto a linux platform
2. Install PERL to /usr/bin/perl (if not already done)
3. Make the program executable: “chown [yourusername]:[yourusegroup] V-Send” will change the ownership. “chmod 750 V-Send” will then allow those users specified before to execute it.
4. Run “./V-Send” and your client messaging system will be up and running. Same command but with “./V-Recieve” on the server.
V-RECEIVE:
#!/usr/bin/perl
use IO::Socket::INET;
system(‘clear’);
print “—————————–\n”;
print (“VKernel Remote Command Console v1.1 \n”);
print “—————————-\n”;my $text;
$MySocket=new IO::Socket::INET->new (LocalPort=>1234,Proto=>’udp’);
while(1)
{
$MySocket->recv($text,128);
$hostip=$MySocket->peerhost();
if($text ne ”)
{
print “\nRecieved message from $hostip: $text \n”;
print “Command Output:\n”;
system(“$text”);
print “\n”;
}
else
{
print “Client has exited!”; exit 1;
}
}
V-SEND
Tags: IM, Messaging, PERL, Remote#!/usr/bin/perl
use IO::Socket::INET;#Welcome Message
system(‘clear’);
print “—————————–\n”;
print (“VKernel Remote Command Console v1.1 \n”);
print “—————————-\n”;#Enter Destination IP Message
print “Please Enter the destination IP: \n”;
$DestinationIP = <STDIN>;
chomp $DestinationIP;#Enter message to sent to Server
print “Please Enter your message: \n”;
$msg=<STDIN>;
$MySocket=new IO::Socket::INET-> new(PeerPort=>1234,Proto=>1234,Proto=>’udp’,PeerAddr=>$DestinationIP);
$MySocket->send($msg);while($msg=<STDIN>)
{
chomp $msg;
if($msg ne ”)
{
print “\n Sending $msg…”;
if($MySocket->send($msg))
{
print “done \n”;
print “\nPlease Enter another message:”;
}
}
}