pkyeck / socket.IO-objc

socket.io v0.7.2 — 0.9.x for iOS and OS X
MIT License
1.97k stars 439 forks source link

xhr-polling/(null)?disconnect under edge networking condition #196

Open dqj opened 10 years ago

dqj commented 10 years ago

My application use this library to connect the socket.io server under edge or gprs carrier, the app will hang over a long time and the error log in the console is:

2014-06-26 19:42:23.564 SocketIOTest[7801:60b] Connecting to socket with URL: localhost:3000/socket.io/1/
2014-06-26 19:42:23.564 SocketIOTest[7801:60b] <SocketIO: 0x170110ce0>
2014-06-26 19:42:33.614 SocketIOTest[7801:60b] ERROR: handshake failed ... The request timed out.
2014-06-26 19:42:33.615 SocketIOTest[7801:60b] Force disconnect at: localhost:3000/socket.io/1/xhr-polling/(null)?disconnect
2014-06-26 19:43:34.525 SocketIOTest[7801:60b] Error during disconnect: Error Domain=NSURLErrorDomain Code=-1001 "The request timed out." UserInfo=0x1780f7c00 {NSUnderlyingError=0x1702455e0 "The request timed out.", NSErrorFailingURLStringKey= localhost:3000/socket.io/1/xhr-polling/(null)?disconnect, NSErrorFailingURLKey= localhost:3000/socket.io/1/xhr-polling/(null)?disconnect, NSLocalizedDescription=The request timed out.}
2014-06-26 19:43:34.526 SocketIOTest[7801:60b] onDisconnect()
2014-06-26 19:43:34.537 SocketIOTest[7801:60b] onError() Error Domain=SocketIOError Code=-6 "The operation couldn’t be completed. (SocketIOError error -6.)" UserInfo=0x170462d80 {NSUnderlyingError=0x1700522d0 "The request timed out."}
pkyeck commented 10 years ago

the handshake fails ... and after that the library has no URL for a forced disconnect - thus using NULL. try fixing the handshake first - after that the rest should work as expected.

dqj commented 10 years ago

You are right. The handshake fails. And I think the reason is the network condition is not good, as i change the carrier from the 3G to GPRS/ EDGE. After I change the carrier to 3G, the app runs well.

dqj commented 10 years ago

Since my app can not shake hand with the server, the app can not send a forced disconnect request to server. While the reason the handshake fails is my app can not connect to server under 2G or 2.5G network. Right?

pkyeck commented 10 years ago

maybe it is a timeout thing? maybe your phone takes too long to "shake hands" with the server and the call is aborted. never ran into this problem myself.

you could try and connect via

- (void) connectToHost:(NSString *)host onPort:(NSInteger)port withParams:(NSDictionary *)params withNamespace:(NSString *)endpoint withConnectionTimeout: (NSTimeInterval) connectionTimeout;

and set the connectionTimeout to something bigger then 15 seconds.

dqj commented 10 years ago

I've set the default connectionTimeout to 30s. But the "shake hands" also fails. Have you ever test the library under these type of carrier network, such as GPRS or EDGE?

Thanks!