How to check socket connection every minute in C ++

I implemented a C ++ project, which: I parse an XML file containing the ip and port of several servers, for each ip and port I first call the connect to server function, in which I connect the TCP sockets to the server, whether the connection is established or not , I make a stream for each ip and port, if the connection is not established, I send the server status that the connection is not established, and if the connection is established, I then make a request to the server and get a response from the server in the stream. This is done after every minute for each thread. Now the problem that I am facing is that if the connection is terminated or the server is powered up, how to make the connection again, which I mean, every one minute before sending a request and receiving a response from the server, I must check if the connection is all there or not. Could you tell me how to do this?

0
source share
1 answer

You can have everything that checks the connection status, and all messages for other classes. Other classes pass it a pointer to a function, and in this method you test the connection, and if it successfully runs the function that you passed. If you do not insert it into the queue that will be started after reconnecting.

0
source

Source: https://habr.com/ru/post/1434774/


All Articles