Hello, I'm trying to write an automated test management tool that drives a device via a TCP/IP socket. I need a listener that runs continuously asynchronously, and occasionally interacts with the sender. Perl threads and the Thread:Queue module would seem to fit the bill nicely. I've written client code based largely on Lincoln Stein's book. I can't get my code to run on Windows (tried pxperl and activestate perl), but it does work on my Solaris8 system. I've created this scrap of code which reproduces the problem. Again, it works on unix but but not windows:
#!/usr/bin/perl5.8.8 -w use strict; use warnings; use threads; use IO::Socket qw(:DEFAULT :crlf); my $host = shift || 'localhost'; my $socket = IO::Socket::INET->new(PeerAddr => $host, PeerPort => 'ftp', Proto => 'tcp', Type => SOCK_STREAM, Timeout => 5) or die "Couldn't connect to remote host: $@\n"; my $listenerThread = threads->create(\&listener, $socket) or die "$@\n +"; while (<STDIN>) { chomp; print $socket $_, CRLF; }; exit(0); sub listener($) { my $s = shift; my $data; $/ = CRLF; syswrite(STDOUT, $data) while sysread($s, $data, 2048); print "\nListener exiting\n"; }; __END__
My program and this snippet always hang up after typing something to STDIN, like "help". Note that I am using the same unix $host in all cases.

Any ideas would be appreciated.

Thanks,
Kevin Zwack


In reply to Sockets and threads, oh my! by KevinZwack

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.