Socket connection offline vs busy
-
Is there a way to make the difference between the server being offline, or it being busy with accepting another connection at the exact same time and not being able to accept another one, so that the client knows it wasn't a problem that the server wasn't online to try again to reach it?
-
Is there a way to make the difference between the server being offline, or it being busy with accepting another connection at the exact same time and not being able to accept another one, so that the client knows it wasn't a problem that the server wasn't online to try again to reach it?
As far as I recall if the server is offline then your code will receive an exception indicating that a connection was refused. If the server is busy the underlying protocol will retry. But you should check the various socket errors that may occur, e.g. the Windows set: Windows Sockets Error Codes (Winsock2.h) - Win32 apps | Microsoft Docs[^].
-
As far as I recall if the server is offline then your code will receive an exception indicating that a connection was refused. If the server is busy the underlying protocol will retry. But you should check the various socket errors that may occur, e.g. the Windows set: Windows Sockets Error Codes (Winsock2.h) - Win32 apps | Microsoft Docs[^].
Aren't those C++ errors? I was asking for Java socket.
-
Aren't those C++ errors? I was asking for Java socket.
-
Aren't those C++ errors? I was asking for Java socket.
-
The best I could find is SocketTimeoutException (Java Platform SE 7 )[^]
I tried to use that, but that exception is thrown if the server is offline but also when it didn't responded to .connect(...) in time.
-
I tried to use that, but that exception is thrown if the server is offline but also when it didn't responded to .connect(...) in time.
Did the exceptions include any message text to explain what was the underlying cause? When I run my Java client against an offline server I get:
Exception in thread "main" java.net.ConnectException: Connection refused: connect
There may be some more useful information at Java Network Programming FAQ[^].
-
Is there a way to make the difference between the server being offline, or it being busy with accepting another connection at the exact same time and not being able to accept another one, so that the client knows it wasn't a problem that the server wasn't online to try again to reach it?
Ping the server; if you get a response, the server is online. "Connecting" is another matter. [https://stackoverflow.com/questions/3584210/preferred-java-way-to-ping-an-http-url-for-availability\](https://stackoverflow.com/questions/3584210/preferred-java-way-to-ping-an-http-url-for-availability)
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
-
Is there a way to make the difference between the server being offline, or it being busy with accepting another connection at the exact same time and not being able to accept another one, so that the client knows it wasn't a problem that the server wasn't online to try again to reach it?