in reply to socket problem? script hangs occasionally...

It would be a good idea to do your print immediately before the send it is explaining; that way it acts as a trace. Wrapping the print/send pair up in a sub will also help you avoid repeating yourself too much. And more prints everywhere for tracing wouldn't hurt either.
printf ("%s\n", 'stuff') if DEBUG_LEVEL > 0 is handy since you can turn it off with one constant and have it still there in case things go wrong later.

I don't see where you test to ensure the socket is writable before you attempt to send, and readable before you read.

I would also suggest packing up the whole message into a string before doing a single send. Fewer places for things to go wrong that way.

Lastly, does the phabrix device perhaps expect a line terminator that you are not providing? If so, it would sit and wait; your buffers would fill up and your reads & writes would start blocking.

Replies are listed 'Best First'.
Re^2: socket problem? script hangs occasionally...
by bgervais (Initiate) on May 03, 2013 at 20:19 UTC

    Thanks, tried concatenating the send before sending the command to the phabrix... but it isn't helping. Despite peppering the code with print statements, it definitely never hangs while inside the subroutine, so the Phabrix doesn't seem to be the issue. rather it seems to hang if it receives another message from the lightspace device before it's done sending the commands to the phabrix... somehow recieving another message too early makes it stop executing once the phabrix subroutine is finished.

    To answer your question about the phabrix though, it does not require any sort of line ending. As soon as it recieves a 20 byte message, it responds ACK or NAK or sometimes not at all, and closes the socket.

    It must have to do with the way I'm reading from the lightspace.

    -ben