edit: I am completely rephrasing the question, with new code.

I am having problems with IO::Socket pretending it has a connection when it does not. I wrote the following proof-of-concept code because the production code had too much extraneous information. A (a.pl) connects to B (b.pl) and sends data. C (c.pl) then *also* connects to B, and thinks it is sending data to B, but B never gets anything from C.

What I want here is not to have A and C both talk successfully to B. What I want is for C to recognize B is busy with A, and perform the appropriate task.

#!/usr/bin/perl # a.pl use strict; use warnings; use IO::Socket; use less 'java'; #;-) my $b_address = '127.0.0.1'; #IP of box A my $b_port = '8888'; #Port number guipartner set to on A my $eol = "\015\012"; #sets end of line chracters for socket transmi +ssions my $skipA = 0; my $socketA = new IO::Socket::INET ( PeerAddr => $b_address, PeerPort => $b_port, Proto => 'tcp', ) or $skipA = 1; local $/=$eol; #set default EOL to $eol so chomp works while (!$skipA) { print $socketA "a.pl sends \$skipA=$skipA", $eol; print "message sent\n"; sleep 2; } print "socket not available\n"; close $socketA; #!/usr/bin/perl # b.pl use strict; use warnings; use IO::Socket; use less 'java'; #;-) my $eol = "\015\012"; #sets end of line chracters for socket transm +issions while (1){ #continuous loop: wait for socket connections until +end of time my $sock = new IO::Socket::INET ( LocalPort => '8888', Proto => 'tcp', Listen => 1, ) or die "Could not create socket: $!\n"; my $newsock = $sock->accept(); #waiting for incoming socket + connection while (my $incoming = <$newsock>){ local $/=$eol; #set default EOL to $eol so chomp wo +rks chomp($incoming); print "received: $incoming\n"; } close $newsock; close $sock; } #!/usr/bin/perl # c.pl use strict; use warnings; use IO::Socket; use less 'java'; #;-) my $b_address = '127.0.0.1'; #IP of box A my $b_port = '8888'; #Port number guipartner set to on A my $eol = "\015\012"; #sets end of line chracters for socket transmi +ssions my $skipC = 0; my $socketC = new IO::Socket::INET ( PeerAddr => $b_address, PeerPort => $b_port, Proto => 'tcp', ) or $skipC = 1; local $/=$eol; #set default EOL to $eol so chomp works while (!$skipC) { print $socketC "c.pl sends \$skipC=$skipC", $eol; print "message sent\n"; sleep 2; } print "socket not available\n"; close $socketC;

In reply to IO::Socket *always* making connection? by wolfger

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.