Hi,

I have a program in which I'm creating an UDP socket with IO::Socket::INET to 
a device on my LAN.  Opening the socket yields no error.  Writing to the 
socket with 'print' works fine.  The device sends data back, and receiving the 
data works fine.

But it doesn't work when the device is offline, like when I pull the network 
cable the device is connected to.  Of course it's obvious that it doesn't 
work, and I'm getting an error message:


print() on closed filehandle GEN0 at ...


My program keeps running nonetheless, which is ok.

Now the problem is that my program needs a way to detect whether the device is 
offline or not so I can make it try to reconnect.

Fortunately, IO::Socket has a 'connected' method, yet unfortunately, the 
method can't really tell whether the socket is actually open or not 
(especially with UDP sockets, I guess).

But then, there must be a way to figure this out because otherwise 'print' 
wouldn't give an error message when the socket is not open.

So how can I either find out in advance if a 'print' will be successful, or how 
can I find out if 'print' was successful or not?  It's like I'm seeing the 
error message and there isn't anything I could do about it.

https://perldoc.perl.org/functions/print says that 'print' would return true 
if successful and doesn't say what it returns otherwise.  It also says that 
"Printing to a closed pipe or socket will generate a SIGPIPE signal."

So I tried to install a signal handler, but either I did that wrong, or no 
signal was generated.  What can I do?




-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to