Question

I made one simple client and server system in which server sends a command and client reply accordingly. Now i want to make it running continuously so that server can send a command to client in a specific time. I don't want to use the windows built-in windows scheduler. The scenrio is something like this..

1) Server sends a command to client.

2) client responds. now client and server is in idle situation.

3) For re sending the command after 1 hour..i need to restart both server and client .exe file again.(i want to make it automatic). Means as the client receives the signal from the server, it replies. and after replying the client goes into idle mode and when again it receives the command it reply. Something like chat as we are always online but in idle situation but when we get the message some window pop out. I want to do something like this.

4) I am using zeromq for communication and my platform is windows-7 and i am using visual studio-7. Utilizing C language.

Was it helpful?

Solution

You simply need to add a main loop in your server to check the time against a defined interval with which you want to send the message. For example:

#include <time.h>

int timeInterval;
int lastInterval;
int nextInterval;

// Main server loop:
while(true) {
    lastInterval = time(NULL);
    nextInterval = lastInterval + timeInterval;

    if(nextInterval <= time(NULL))
        SendMessage();
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top