Hi,

I am a newbie in Perl, used it only to work with strings in the past, but now I am doing a MSc work that makes massive usage of threads and sockets.

My goal is to pass a socket handle to a thread, so the thread can recv data.

I have read something about shared objects (where IO::Socket is not available to pass). Is there a way to pass a socket handle to a thread?

I create the socket:
$server = IO::Socket::INET->new( LocalAddr=>'localhost', LocalPort=>$port, Type=>SOCK_STREAM, Proto=>'tcp', Listen=>10 ); sub protocol($server) { while(1) { if ($server->connected()) { print "Socket is here :)"; } $server->recv($data,1024); @recvData = split(/:/,$data); print $data; print $recvData; } } while(1) { print "UP\n"; $server->accept(); print $server->connected(); $p = threads->create(\&protocol => $server); }

In reply to Pass a IO::Socket handle to a thread by bsdmeister

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.