Link to home
Start Free TrialLog in
Avatar of jewee
jewee

asked on

Using block - Perl...help!


Here is part of my script:
How do I modify the socket to make it nonblocking?  What happens is that it hangs(waits) for a period of time!
            
my $socket = new IO::Socket::INET (
                                  PeerAddr => '10.0.0.5',
                                  PeerPort => '2222',
                                  Proto => 'tcp',
                                 );


@requestBytes=( 0xD0, 0x00, 0x00, 0x00,
                0x28, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00,
                0x65, 0x00, 0x00, 0x00,  
                0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00,
                0x07, 0x00, 0x00, 0x00 );
               
#print "@requestBytes\n";

$requestMsg = pack 'C*',@requestBytes;

  $socket->write($requestMsg);


while($socket->connected) {
  $buffer=0;
  #Retrieve only header
  $socket->read($buffer,40);
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jhurst
jhurst

If you want your script to go on then surely it needs the data.

If you can continue and accept the fact that the data is not there then why are you asking for it.

If you want to "time out" then I would sue an alarm() to set a timeout and go on even if the request does not finish in the time required.