hello everyone.....
when i went to hostel my parents used to call me every other minute espl my sister....
once my father told me that the phone bill has increased at least five fold
so i decided to make a chatting software so that we can talk anytime.......
here it goes
the host
use IO::Socket; #use the socket module
use strict; #am bit careless so i need this
my $socket=new IO::Socket::INET(
LocalAddr=>'<my IP>' ,
LocalPort=>8080,
Listen=>1,
) or die "cannot create host\n";
my ($client,$scrap_out,$scrap_in);
while($client=$socket->accept())
{
while(1)
{
#now recieve the messeage
$scrap_in=<$client>;
print "scrap_in:\t$scrap_in\n";
print "scrap_out:\t";
$scrap_out=<>;
print $client $scrap_out;
if($scrap_out=~/'bye'/i or $scrap_in=~/'bye'/)
{close $socket and die "connection closed\n";}
}
}
the client
use IO::Socket;
use strict;
print "enter host name to connect to:\t";
my $hostname=<>;
my $socket= new IO::Socket::INET(
PeerAddr=>$hostname,
PeerPort=>8080,
Reuse=>1,
) or die "cannot connect to host at this time\n";
my($scrap_in,$scrap_out);
while(1)
{
print "scrap_out:\t";
$scrap_out=<>;
print $socket $scrap_out;
$scrap_in=<$socket>;
print "scrap_in:\t$scrap_in\n";
if($scrap_in=~/'bye'/i or $scrap_out=~/'bye'/i)
{close $socket and die "connection ended\n";}
}
so this way we chat everyday in the evening and even my dad installed perl and this program in many of his friend's and relative's lappys and he told me that the phone bill is reduced five folds!!!!
coooolll
ps:- the <my ip> string is the ip given to me by my college server and i know this is bit clumsy but this dates back to when i first started network programming in perl
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.