I must be missing something very basic here, but I'm having a problem with connecting to a single threaded server based on IO::Socket. Basically, the following does not block until the other side does a "$server->accept".
my $sock = new IO::Socket::INET( PeerAddr => '127.0.0.1', PeerPort => 12000, Proto => 'tcp', Blocking => 1); print $sock "Hello\n";
I had expected that if the server was written as such
my $server = IO::Socket::INET->new( LocalPort => 12000, Proto => 'tcp', Listen => SOMAXCONN, Reuse => 1 ); die $! unless $server; while (my $sock = $server->accept) { print "Connected to sock\n"; print while <$sock>; }
Once it had accepted one connection, any subsequent ones would block until it could accept() again.

I am obviously wrong here.

The above is contrived, of course, but what I want is the part that connects to block until the server is finished with it's current request.

As I said, I'm missing something obvious I'm sure, so please help out a brain-addled fellow monk.

EDIT

Here is the test code I wrote in it's entirety:

use strict; use warnings; use IO::Socket::INET; if ($ARGV[0] == 1) { my $server = IO::Socket::INET->new( LocalPort => 12000, Proto => 'tcp', Listen => SOMAXCONN, Reuse => 1 ); die $! unless $server; while (my $sock = $server->accept) { print "Connected to sock\n"; print while <$sock>; } } if ($ARGV[0] == 2) { my $sock = new IO::Socket::INET( PeerAddr => '127.0.0.1', PeerPort => 12000, Proto => 'tcp', Blocking => 1 ); print "sock is $sock\n"; }
Then what I did was this:
$ perl SocketT.pl 1 (to launch as a server) $ telnet localhost 12000 (in another window, to tie up the server) $ perl SocketT.pl 2 (to test if it would connect and print out)

mr.nick ...


In reply to IO::Socket connect fails to block by mr.nick

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.