GoldenNewby
GoldenNewby

Reputation: 4452

Is it possible to check if a TCP connection disconnected without writing to it?

I am wondering if it possible to determine if an accepted socket connection has been disconnected without trying to write to it.

IO::Select still indicates that the socket can be written to with can_write, even after the socket connection has been lost.

Is it possible to check if a TCP connection has been disconnected without writing to it (in the situation where there is an unplanned internet outage).

Upvotes: 2

Views: 268

Answers (2)

weismat
weismat

Reputation: 7411

This is more a TCP than a Perl issue.

Events like a disconnected cable/internet connection do not lead to a TCP event. Thus you must write to a TCP connection to be sure that it is still connected. You might add a ping/echo message for the sole porpose to know that the connection is still available.

Upvotes: 3

Femi
Femi

Reputation: 64700

Generally, no. You'll usually only get a failure when you write: if you never write, it will just sit there. If you entirely lose network connectivity I've seen errors pop up (on Windows: haven't tried it on Linux) but you're typically required to try writing to it to verify that its alive.

Upvotes: 1

Related Questions