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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |