0

I am calling a web service using a socket call. I want to prevent my client app from 'hanging' until the socket call times out if the service is not running. The app is working fine if the service is running. The create socked and connect are successful even if the service is not running. ALso, what header library would need to be included?

//Create the Socket
sockfd = socket(AF_INET, SOCK_STREAM, 0);

if (sockfd < 0)
{
    printf("errno %d: %s\n",errno,strerror(errno));
    set_output_data(in_out_address->error,
                    "E991",
                    ERROR_SIZE);
    return;
};
printf("errno %d: %s\n",errno,strerror(errno));
printf("sockfd %d: %s\n",sockfd,"socket call");

//Connect
errno=0;
connresult = connect(sockfd,(struct sockaddr *)&server_addr,
                                      sizeof(server_addr));
if (connresult < 0)
{
    printf("errno %d: %s\n",errno,strerror(errno));
    set_output_data(in_out_address->error,
                    "E992",
                    ERROR_SIZE);
    return;
}
printf("errno %d: %s\n",errno,strerror(errno));
printf("connresult %d: %s\n",connresult,"connection call");

// check if service is running before we send data

1 Answers1

0

Web services work over HTTP. You have to send HTTP request before getting any reply. I would suggest looking into some library like gsoap instead of trying to do this by hand.

Nikolai Fetissov
  • 82,306
  • 11
  • 110
  • 171
  • I am actually using the HTTP send with XML data, but the app is hanging waiting for a 'receive' reply when the service is not running. I'm trying to prevent the hang, but don't know the correct 'C' syntax to check the status of the service. – JustFillingIn May 23 '11 at 11:40
  • There's no "C syntax" for it. The best you can do is time out. Waiting in `select()` or `poll()` is one way of doing it. – Nikolai Fetissov May 23 '11 at 12:53