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

标签 iphone sockets connect gsoap errno

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

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

通过调试器进行的工作表明该错误来自connect()socket.h方法。
我不太了解,当我启动另一个应用程序(例如safari)时,设备已连接到Internet。加载网页后,我的应用程序的连接正常。

这是我正在使用的代码:
//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;
}

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

最佳答案

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

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.

关于iphone - 通过socket.h调用connect()时,使用GSoap返回EHOSTUNREACH,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3459528/

相关文章:

ios - 使用 xcodebuild 命令从 Cordova 项目创建 IPA

ios - iOS 10 邮件客户端不接收媒体查询

c - 绑定(bind)到 C 中的特定 IP for ubuntu

Node.js 在生产中使用 forever 和 connect 的 vhosts/nginx 替代方案?

c++ - Qt C++ 将具有非空签名的信号连接到 lambda

iphone - 即使 Wi-Fi 可用,也强制 iPhone 上的 WWAN 连接

iphone - 在 subview 上设置委托(delegate)

python - TCP Socket Server客户端连接fd会不会导致内存泄露?

java - TCP客户端/服务器

node.js - Connect/node.js - 创建一个简单的服务器