开发者

C program-How do I check if a web service is running

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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜