maybe the both server and client code will help:
client :
use threads;
use IO::Socket;
my $so = new IO::Socket::INET( PeerAddr => '127.0.0.1',
PeerPort => 1300,
Proto => 'tcp',
Reuse => 1,);
die "Socket Error: $!\n" unless $so;
my $thread = threads->create(\&start_thread);
my $thread1 = threads->create(\&start_thread1);
sub start_thread {
while(my $txt=<$so>){print "server : $txt";}
}
sub start_thread1 {
while(my $msg = <STDIN>){ print $so "$msg"; }
}
$thread->join();
$thread1->join();
server:
use threads;
use IO::Socket;
my $so = new IO::Socket::INET(LocalPort => '1300',
Proto => 'tcp',
Listen => 10,
Reuse => 1,);
die "Socket Error: $!\n" unless $so;
while (my $client = $so->accept()) {
my $thread = threads->create("start_thread");
my $thread1 = threads->create("start_thread1");
print $so "connected\n";
sub start_thread1 {
while(my $get=<$client>){print "client : $get";}
}
sub start_thread {
while(my $msg = <STDIN>){ print $so "$msg"; }
}
$thread->join();
}
|