• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 189
  • Last Modified:

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);
0
jewee
Asked:
jewee
1 Solution
 
ozoCommented:
If the socket does not have 40 bytes ready for you to read, what would you want to do other than wait for it to send you the data?

If the read is never returning, it may be because your write never flushed its buffer to send it to your peer.
If that's the problem you may want to set
  $socket->autoflush(1);
before writing
0
 
jhurstCommented:
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.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now