in reply to Re: socket with threads problem
in thread socket with threads problem

dunno why but ur both codes didnt work and not with my program i've made a simple server that gets a handle from client and send him the msg back and it's just stuck try your own maybe there is another thing maybe a client cant get a m,sg from the server but whats the problem

Replies are listed 'Best First'.
Re^3: socket with threads problem
by wavenator (Novice) on Oct 10, 2007 at 18:46 UTC
    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(); }