通过 socket.h 调用 connect() 时,使用 GSoap 返回 EHOSTUNREACH

发布于 2024-09-13 17:41:46 字数 1893 浏览 11 评论 0原文

我目前正在构建一个基于 Gsoap 工具包的 iPhone 应用程序以连接到一个网络服务。一切正常,除了当我在设备上断开并重新连接 3g 后尝试连接到我的服务时,我得到:

SOAP 1.1 fault: SOAP-ENV:Client [no subcode]
"Connection refused"
Detail: connect failed in tcp_connect()

通过调试器显示错误来自 socket 的 connect() 方法.h。 我不太明白,当我启动另一个应用程序(如 safari)时,设备会连接到互联网。加载网页后,我的应用程序的连接工作正常。

这是我正在使用的代码:

//GSoap initialization
    struct soap soap; 
    soap_init(&soap);
    soap.connect_timeout = 0;  
    soap.send_timeout = 0; 
    soap.recv_timeout = 0;


// objects request & response
// struct types can be foundin soapStub.h
struct _ns1__GetAuthentification requete;
struct _ns1__GetAuthentificationResponse reponse;

// init request
requete.ConnectPass = (char *) [connectPass UTF8String];
requete.Login = (char *) [login UTF8String];
requete.Password = (char *) [password UTF8String];
requete.soap = &soap;

// request callback. returns SOAP_OK if something has been returned
if(soap_call___ns1__GetAuthentification(&soap,NULL,NULL, &requete,&reponse) == SOAP_OK){

    //then we build the result
    NSLog(@"Yay!");

    soap_end(&soap); // remove deserialized data and clean up
    soap_done(&soap); // detach the gSOAP environment

    return authResult;

}
else {

    //NSLog(@"Soap Error : GetAuthentification");
    // We try to see if there's any problem. @catch statements are here just to keep note of the concerned
    // exceptions for each request. No utility for the code.
    @try {
        [self processFault:&soap];
    }
    @catch (MMWrongId * e) {
        @throw e;
    }
    @catch (MMConnectionFailed * e) {
        @throw e;
    }
    @catch (MMGetAuthentificationFault * e) {
        @throw e;
    }


    return nil;
}

我是否缺少任何特定的标志/选项?

I'm currently building an iPhone app based on Gsoap toolkit to connect to a webservice. Everything works fine except when I try to connect to my service after disconnecting and reconnecting 3g on the device, I get :

SOAP 1.1 fault: SOAP-ENV:Client [no subcode]
"Connection refused"
Detail: connect failed in tcp_connect()

Working through the debugger shows that the error comes from connect() method of socket.h.
I don't really understand, when I launch another app like safari, the device is connected to the Internet. And after loading a web page, my app's connection works fine.

Here is the code I'm using :

//GSoap initialization
    struct soap soap; 
    soap_init(&soap);
    soap.connect_timeout = 0;  
    soap.send_timeout = 0; 
    soap.recv_timeout = 0;


// objects request & response
// struct types can be foundin soapStub.h
struct _ns1__GetAuthentification requete;
struct _ns1__GetAuthentificationResponse reponse;

// init request
requete.ConnectPass = (char *) [connectPass UTF8String];
requete.Login = (char *) [login UTF8String];
requete.Password = (char *) [password UTF8String];
requete.soap = &soap;

// request callback. returns SOAP_OK if something has been returned
if(soap_call___ns1__GetAuthentification(&soap,NULL,NULL, &requete,&reponse) == SOAP_OK){

    //then we build the result
    NSLog(@"Yay!");

    soap_end(&soap); // remove deserialized data and clean up
    soap_done(&soap); // detach the gSOAP environment

    return authResult;

}
else {

    //NSLog(@"Soap Error : GetAuthentification");
    // We try to see if there's any problem. @catch statements are here just to keep note of the concerned
    // exceptions for each request. No utility for the code.
    @try {
        [self processFault:&soap];
    }
    @catch (MMWrongId * e) {
        @throw e;
    }
    @catch (MMConnectionFailed * e) {
        @throw e;
    }
    @catch (MMGetAuthentificationFault * e) {
        @throw e;
    }


    return nil;
}

Am I missing any particular flag/option?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

温柔嚣张 2024-09-20 17:41:46

对于那些遇到同样问题的人,我找到了解决方案。 Michael Lasmanis 对此提供了巨大的帮助。这是他的回答:

这是我不再向 iPhone 新 iPhone 开发人员推荐 gsoap 的原因之一。 gsoap 使用较低的 bsd 套接字并绕过较高级别的 iphone api。它是管理互联网连接状态的更高级别的 API,这就是为什么如果您先启动 Safari,那么一切都会正常。最简单的解决方法是在调用 gsoap 之前使用 nsurlconnection 打开到知名站点的 http 连接。

For those who encounter the same issue, I got a solution. Michael Lasmanis has been a huge help for this one. Here is his answer :

this is one of the reasons i no longer recommend gsoap for iphone new iphone developers. gsoap uses the lower bsd sockets and bypasses the higher level iphone apis. it is the higher level api that manage the state of the internet connectivity which is why if you start safari first, then everything works. the easiest workaround is to use nsurlconnection to open a http connect to a well know site before calling gsoap.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文