It's a server-client code. The client should wait for the server, and if there's no response, then send a new request. There's a 2 second wait. It's UNIX.
I've been looking at some select() examples, but I'm not really sure... I found this example.

#include <sys/types.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <stdio.h>

#define S1READY 0x01
#define S2READY 0X02

waittoread(int s1,int s2)
   fd_set fds;
   struct timeval timeout;
   int rc, result;

      /* Set time limit. */
   timeout.tv_sec = 2;
   timeout.tv_usec = 0;
      /* Create a descriptor set containing our two sockets.  */
   FD_SET(s1, &fds);
   FD_SET(s2, &fds);
   rc = select(sizeof(fds)*8, &fds, NULL, NULL, &timeout);
   if (rc==-1) {
      perror("select failed");
      return -1;

   result = 0;
   if (rc > 0)
      if (FD_ISSET(s1, &fds)) result |= S1READY;
      if (FD_ISSET(s2, &fds)) result |= S2READY;

   return result;

Would this work? And would this be the most efficient way to do ?

3 Years
Discussion Span
Last Post by iamthwee
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.