#!/usr/bin/perl -w use warnings; use strict; use threads; use IO::Socket; my $so = new IO::Socket::INET(LocalPort => '1300', Proto => 'tcp', Listen => 10, Reuse => 1,); my $client; die "Socket Error: $!\n" unless $so; sub start_thread1 { print "thread1 started\n"; while(my $get=<$client>) { print "client : $get"; } print "thread1 ended\n"; } sub start_thread { print "thread started\n"; print $client "OK ... whaddaya want?\n"; while (my $msg = ) { print $client $msg; } print "thread ended\n"; } while ($client = $so->accept()) { my $thread = threads->create("start_thread"); my $thread1 = threads->create("start_thread1"); # This message appears to go nowhere ... we should use $client! print $so "connected ... whatcha want?\n"; print "connected\n"; $thread->join(); } #### #!/usr/bin/perl -w use warnings; use strict; 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 { print "thread\n"; while (my $txt=<$so>) { print "server : $txt"; } print "endthread\n"; } sub start_thread1 { print "thread1\n"; print $so "Client connected!\n"; while (my $msg = ) { print $so "$msg"; } print $so "Client disconnected!\n"; print "thread1end\n"; } $thread->join(); $thread1->join();