in reply to Check connection state prior to send data

Dear community, thank you all to partecipate, I would like to share my (very simply) solution to my question. The following code works perfect and suit my needs.

BTW, the concept behind solution is simple too:
-- Open a socket
-- Server is listining?
---- YES: OK Connect
---- NO: Enter in loop until Server will be ready
-- Send data
-- Is there any response from server?
---- YES: Continue sending loop
---- NO: (Empty Response): Call OpenSocket and wait untill Server will be ready again.
#!/usr/bin/perl use IO::Socket; my $sock1; sub OpenSocket{ while ( !$sock1 ) { $sock1 = IO::Socket::INET->new ( Proto => "tcp", PeerAddr => "192.168.10.7", PeerPort => "8000", Timeout => "1") } } ################ START SCRIPT ################# OpenSocket(); sleep(1); my $str="DATA TO SEND" while(1) { $sock1->send($str); sleep(1); $sock1->recv($channel1, 128); if ( !$channel1 ) { $sock1->shutdown(2); $sock1=""; print "DISCONNECTED... I'M RECONNECTING AND RESEND PREVIOUS PACKET +\n"; OpenSocket(); sleep(1); $sock1->send($str); } } close($sock1);

Replies are listed 'Best First'.
Re^2: Check connection state prior to send data
by BrowserUk (Patriarch) on Sep 26, 2016 at 07:51 UTC

    What do you think this code does? $sock1  = shift; Ie. Where are you shifting the value you are assigning to $sock1 from?


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
    In the absence of evidence, opinion is indistinguishable from prejudice.
      Thank you, that was a typo left there from previous tests. I modified my post with the right code. That one works perfect also with one or more parameters.