A
A
Alexey2016-07-26 21:03:06
C++ / C#
Alexey, 2016-07-26 21:03:06

How to catch incorrect server shutdown?

I catch the exit from the program through an event using ConsoleEvent:

public enum ConsoleEvent
    {
      CTRL_C = 0,
      CTRL_BREAK = 1,
      CTRL_CLOSE = 2,
      CTRL_LOGOFF = 5,
      CTRL_SHUTDOWN = 6
    }

That is, the client understands that the server is turned off, and when the server is turned on, the client connects automatically. But if the program exits incorrectly (for example, when the process is terminated from the dispatcher), the client simply turns off and that's it. And, it seems to me that the problem is precisely that the client incorrectly perceives the shutdown of the server. Help deal with this problem. Maybe I'm digging in the wrong forest at all.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Stanislav Makarov, 2016-07-26
@alexey_sigida

We will assume that we are talking about a client and a server in the context of interaction via the TCP protocol (if not, please specify the question).
Tell the client that the server is shutting down normally, and the client will know it makes sense to reconnect. If the server disconnects and does not send such a message, the client considers that the server has shut down abnormally and does not reconnect. Moreover, you can tell the client in how many seconds/minutes/hours you can connect to the server again - the client will not take a steam bath and knock on the closed gate until the server has risen yet.

M
MrDywar Pichugin, 2016-07-26
@Dywar

No way.
The process can be assured or put to sleep, and no one will report anything.
Only if there is another process that will monitor the first one.

L
LiptonOlolo, 2016-07-27
@LiptonOlolo

Well, I don’t know, I personally use the NetSockets library and everything is very conveniently implemented there, look in its direction.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question