Hello monks! im here again because i can't really make a messenger in perl i have a very limited amount of networking in perl i was trying to create a messenger in perl where you can select who you want to chat e.g i want to chat John so i just want to click his name and start chatting. So here's my code i push all the filehandles in 1 array which it turns to group chat. But i don't want group chat but i don't know what to do with this filehandles!
#!/usr/bin/perl
use strict;
use warnings;
use IO::Socket::INET;
use threads;
use threads::shared;
my @clients : shared;
@clients=();
my $socket=new IO::Socket::INET(
LocalAddr=>'localhost',
LocalPort=>7777,
Proto=>'tcp',
Timeout=>7200,
Listen=>7,
Reuse=>1
) || die "$!\n";
while(1){
my $client;
$client=$socket->accept;
my $peerhost=$client->peerhost;
my $peerport=$client->peerport;
print "$peerhost:$peerport\n";
my $f_client=fileno $client;
push(@clients,$f_client);
my $thr=threads->create(\&accept,$client,$peerhost,$f_client);
}
sub accept{
my ($client1,$peerhost1,$f_client1)=@_;
if($client1->connected){
while(<$client1>){
foreach my $fn(@clients){
open(my $fh, ">&=$fn") || die "$!\n";
print $fh "$_";
}
}
}
}
-
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.
|