Will this work for you?

<server>
use threads;
use strict;
use IO::Socket::INET;

my ($sock, $s, $v_mode);

$sock = IO::Socket::INET->new( Listen => 5,
                                   LocalPort => 9000,
                                   Proto     => 'tcp',
                                   Reuse     => 1,
                                 );

LOOP: while (1) {
  print "waiting for next connection.\n";

  while(($s = $sock->accept())) {
    my ($peer_cert, $subject_name, $issuer_name, $date, $str);
    
    if( ! $s ) {
      print "error: '$!'.\n";
      next;
    }

    print "connection opened ($s).\n";
    sub mthread {
        my $tid = threads->tid;
        $str = "thread $tid is answering you\n";
        $s->write($str, length($str));

        $s->close();
        print "\t connection closed for $tid.\n";
        sleep(3);
    }
    threads->create('mthread')->detach;
    next LOOP;
  }
}

$sock->close();

print "loop exited.\n";
<server/>


Jay Flowers
Integic
Health Care


-----Original Message-----
From: Elizabeth Mattijsen [mailto:[EMAIL PROTECTED]] 
Sent: Wednesday, October 09, 2002 11:50 AM
To: Ray Hilton; 'Perl-Ithreads'
Subject: Re: IO::Socket and iThreads (and Thread::Pool)

At 04:25 PM 10/9/02 +0100, Ray Hilton wrote:
>Hi, me again, today im trying to set up a daemon to sit and listen on a
>TCP/IP port and create a new job whenever a new socket is established.
>The problem here is some how passing the socket handle from the main
>loop to the thread.
>
>Now, you cannot share or serialize GLOBs so how can I go around this?
>Normally I would defer the creation of a resource handle until within
>the thread, but as the socket is being created when a client connects
>(before the thread is spawned), how can I get around this?  Ideas would
>be very welcome :)

Check out CPAN for FDPasser.  I have a hunch we should be able to work
out 
something with that...  but havne't got the tuits right now to look at
it 
myself...


Liz

Reply via email to