codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  Chat application  ksaswathy at 14:39 on Thursday, October 25, 2007
 

I want to develop a chat application using perl.
My code is given below.
If I tried this code in two separate machines,it won't work.Anyone help me.


use strict;
use warnings;
use threads;
use IO::Socket::INET;
my $port = 7745;
my $thread = threads->create("server_thread");
my $thread1 = threads->create("client_thread");
sub server_thread {
my %params = (
LocalHost => '10.10.97.20',
LocalPort => $port,
Proto => 'tcp',
Listen => 1,
Reuse => 1,
ReuseAddr => 1,
);
my $so = new IO::Socket::INET(%params);
die "Server Socket Error: $!\n" unless $so;
print STDERR "[Server Socket Connected]\n";
my $client = $so->accept();
$client->autoflush(1);
while (1) {
my $txt = <$client>;
last unless defined($txt);
chomp $txt;
last if ($txt eq 'quit');
print "server : $txt\n";
}
print "[Server finished]\n";
}
sub client_thread {
sleep 1; # Give the server a head start
my %params = (
'PeerAddr' => '10.10.97.20',
'PeerPort' => $port,
'Proto' => 'tcp',
'ReuseAddr' => 1,
);
my $so = new IO::Socket::INET(%params);
$so->autoflush(1);
die "Client Socket Error: $!\n" unless $so;
print STDERR "[Client Socket Connected]\n";
while (my $msg = <STDIN>) {
chomp $msg;
last if ($msg eq 'quit');
print $so "$msg\n";
}
print "[Client finished]\n";
}
$thread->join();
$thread1->join();














CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums
//








Recent Forum Threads
•  Remote program execution using cgi-perl
•  Chat application
•  How to send multiple perameters in SOAP request.
•  Java code for Insert picture on the table in spreadsheet
•  Re: Problem with concatenation
•  how to genrates the crystal report by sending a id at runtime
•  help me
•  pls help me with this..
•  Re: Security - Code verify


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2007