pkyeck / socket.IO-objc

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

Websocket not getting connected. #15

Closed quintet closed 12 years ago

quintet commented 12 years ago

Iam getting a error while trying to connect to websocket. The delegate 'webSocket:(WebSocket )ws didFailWithError:(NSError )error ' is fired with a null error. Can someone explain why I'm not able to connect?

pkyeck commented 12 years ago

what is your setup? is your socketserver running (correctly)? can you connect using the browser?

quintet commented 12 years ago

Yes my socket server is running. Right now I am able to connect most of the time but on rare occasions (say once in about 6 tries) I am getting above mentioned error. The NSError *error parameter in webSocket:(WebSocket *)ws didFailWithError:(NSError *)error is returning as nil.

And in even rarer cases the same delegate fires with NSError time out error

ERROR: Connection failed with error ... Read operation timed out

One other thing I noticed the timeout error only fires after approximately 5 seconds of delay. But when NSError is nil, the delegate gets fired as soon as [_webSocket open]; is called.

claaslange commented 12 years ago

I'm having the same problem as quintet. My socket server is definitely running and there are no problems connecting to it witch Chrome on Mac OS X, Windows and Safari on iPad. When it fails I'm seeing either ERROR: Connection failed with error ... Read operation timed out or ERROR: Connection failed with error ... nil

in Xcode's debug console.

I switched to the new ARC-Version just 5 minutes ago and will see if the problem still persists. So far (about 9 tries) it seems to be working.

EDIT:

The new version does not help. Still seeing the ERROR: Connection failed with error ... Read operation timed outerror

pkyeck commented 12 years ago

i just made some small changes to the way the handshake is done - could you please do a pull and check whether or not the problem is still there?

quintet commented 12 years ago

Seems like you have updated the ARC version. Since our project runs on Non ARC version we couldn't run the changes.

claaslange commented 12 years ago

I checked it, unfortunately the error still persists. Worked 14 times like a charm, but the 15th time I got:

2012-06-06 11:37:33.133 App[2541:707] Connecting to socket with URL: http://home.pb:80/socket.io/1/?t=16807
2012-06-06 11:37:33.309 App[2541:707] requestFinished() 1157881484256392746:60:60:websocket,flashsocket,htmlfile,xhr-polling,jsonp-polling
2012-06-06 11:37:33.311 App[2541:707] sid: 1157881484256392746
2012-06-06 11:37:33.315 App[2541:707] heartbeatTimeout: 67.000000
2012-06-06 11:37:33.317 App[2541:707] transports: (
    websocket,
    flashsocket,
    htmlfile,
    "xhr-polling",
    "jsonp-polling"
)
2012-06-06 11:37:33.322 App[2541:707] Opening ws://home.pb:80/socket.io/1/websocket/1157881484256392746
2012-06-06 11:37:38.342 App[2541:707] ERROR: Connection failed with error ... Read operation timed out
2012-06-06 11:37:38.343 App[2541:707] onDisconnect()
2012-06-06 11:37:38.346 App[2541:707] -[KMLMainViewController socketIODidDisconnect:] [Line 327] Disconnected from socket 
pkyeck commented 12 years ago

@claaslange what did the socket.io server log. the handshake was successful, the socket-connection after that failed.

claaslange commented 12 years ago

Currently working on the logs. Got some new error, seems to be the same quintet experiences.

2012-06-06 15:43:38.206 App[3600:707] Connecting to socket with URL: http://home.pb:80/socket.io/1/?t=16807
2012-06-06 15:43:38.387 App[3600:707] requestFinished() 9531394381379498557:60:60:websocket,flashsocket,htmlfile,xhr-polling,jsonp-polling
2012-06-06 15:43:38.389 App[3600:707] sid: 9531394381379498557
2012-06-06 15:43:38.392 App[3600:707] heartbeatTimeout: 67.000000
2012-06-06 15:43:38.395 App[3600:707] transports: (
    websocket,
    flashsocket,
    htmlfile,
    "xhr-polling",
    "jsonp-polling"
)
2012-06-06 15:43:38.400 App[3600:707] Opening ws://home.pb:80/socket.io/1/websocket/9531394381379498557
2012-06-06 15:43:38.425 App[3600:707] Connection opened.
2012-06-06 15:43:38.428 App[3600:707] onData 1::
2012-06-06 15:43:38.430 App[3600:707] setTimeout()
2012-06-06 15:43:38.456 App[3600:707] connect
2012-06-06 15:43:38.457 App[3600:707] onConnect()
2012-06-06 15:43:38.459 App[3600:707] onConnect() >> End points do not match, resending connect packet
2012-06-06 15:43:38.460 App[3600:707] send()
2012-06-06 15:43:38.462 App[3600:707] send() >>> 1::/Photos
2012-06-06 15:43:38.470 App[3600:707] onData 1::/Photos
2012-06-06 15:43:38.472 App[3600:707] setTimeout()
2012-06-06 15:43:38.474 App[3600:707] connect
2012-06-06 15:43:38.476 App[3600:707] onConnect()
2012-06-06 15:43:38.477 App[3600:707] -[KMLMainViewController socketIODidConnect:] [Line 321] Connection with socket
2012-06-06 15:43:38.479 App[3600:707] doQueue() >> 0
2012-06-06 15:43:38.481 App[3600:707] setTimeout()
2012-06-06 15:43:51.863 App[3600:707] ERROR: Connection failed with error ... (null)
2012-06-06 15:43:51.865 App[3600:707] onDisconnect()
2012-06-06 15:43:51.869 App[3600:707] Connection closed.
2012-06-06 15:43:51.871 App[3600:707] onDisconnect()
2012-06-06 15:43:51.873 App[3600:707] -[KMLMainViewController socketIODidDisconnect:] [Line 327] Disconnected from socket
claaslange commented 12 years ago

@pkyeck I got the following logs on the server:

 info  - handshake authorized 19770665261693374496
 debug - setting request GET /socket.io/1/websocket/19770665261693374496
 debug - set heartbeat interval for client 19770665261693374496
 warn  - Invalid websocket key: "wC I-q"X`&4'73|$M 527  9 11".
 info  - transport end (undefined)
 debug - set close timeout for client 19770665261693374496
 debug - cleared close timeout for client 19770665261693374496
 debug - cleared heartbeat interval for client 19770665261693374496
 warn  - Invalid websocket key: ")-B` h^[19"'1 6(#584V r414".

This caused the following error:

ERROR: Connection failed with error ... null

pkyeck commented 12 years ago

is this with the ARC or non-ARC version?

claaslange commented 12 years ago

It's with the ARC version.

claaslange commented 12 years ago

Here is the log for the time out error:

info  - handshake authorized 968199958930396315
   debug - setting request GET /socket.io/1/websocket/968199958930396315
   debug - set heartbeat interval for client 968199958930396315
   debug - client authorized for 
   debug - websocket writing 1::
10.10.0.20 - - [Thu, 07 Jun 2012 10:47:16 GMT] "GET /photos.json HTTP/1.1" 200 - "-" "PrismaViewer/1.0 CFNetwork/548.1.4 Darwin/11.0.0"
   info  - transport end (socket end)
   debug - set close timeout for client 968199958930396315
   debug - cleared close timeout for client 968199958930396315
   debug - cleared heartbeat interval for client 968199958930396315
   debug - discarding transport

In Xcode I see the following:

2012-06-07 12:47:16.757 App[4430:707] Opening ws://home.pb:80/socket.io/1/websocket/968199958930396315
2012-06-07 12:47:16.774 App[4430:707] #####################
2012-06-07 12:47:16.775 App[4430:707] KEY:
2012-06-07 12:47:16.777 App[4430:707] ^   J(*% U9D   '-' /7 /2545 680
2012-06-07 12:47:16.779 App[4430:707] #####################
2012-06-07 12:47:16.781 App[4430:707] #####################
2012-06-07 12:47:16.783 App[4430:707] KEY:
2012-06-07 12:47:16.784 App[4430:707] -+  J)L #!%20K95Y+8.4- 6756
2012-06-07 12:47:16.786 App[4430:707] #####################
2012-06-07 12:47:21.792 App[4430:707] ERROR: Connection failed with error ... Read operation timed out
2012-06-07 12:47:21.794 App[4430:707] onDisconnect()
2012-06-07 12:47:21.796 App[4430:707] -[KMLMainViewController socketIODidDisconnect:] [Line 328] Disconnected from socket

The ######## key thing is added by me. I'm currently looking if I can find a pattern in the not accepted keys.

quintet commented 12 years ago

Well this is the log we are getting, We are running non ARC version.

2012-06-08 09:27:19.658 MyApp[585:11903] Connecting to socket with URL: http://50.97.85.225:80/socket.io/1/?>t=563613512 2012-06-08 09:27:20.205 MyApp[585:11903] requestFinished() 10805291131983251033:60:60:websocket,xhr->polling,jsonp-polling,htmlfile,flashsocket 2012-06-08 09:27:20.205 MyApp[585:11903] sid: 10805291131983251033 2012-06-08 09:27:20.205 MyApp[585:11903] heartbeatTimeout: 67.000000 2012-06-08 09:27:20.206 MyApp[585:11903] transports: ( websocket, "xhr-polling", "jsonp-polling", htmlfile, flashsocket ) 2012-06-08 09:27:20.220 MyApp[585:11903] Opening >ws://50.97.85.225:80/socket.io/1/websocket/16754975251191513560 2012-06-08 09:27:21.958 MyApp[585:11903] ERROR: Connection failed with error ... (null) 2012-06-08 09:27:21.958 MyApp[585:11903] onDisconnect()

We don't have any control over the server side, but already many desktop and web clients are running successfully under that server. We used to get this error in infrequent intervals before but for the past 24 hours the connection is failing every time.

quintet commented 12 years ago

There was a proxy setup in our network and when we tried to connect under that , we never got it to connect. Every time we got message ERROR: Connection failed with error ... (null) . Then we removed the proxy setup for our iPhone, and it got connected sometimes. We never had any firewall rules.

It is still not connecting always, getting the same error about once in 6 tries.

pkyeck commented 12 years ago

@quintet i tried your server and sometimes got this:

2012-06-09 09:58:03.523 SocketTesterNonARC[8271:f803] Connecting to socket with URL: http://50.97.85.225:80/socket.io/1/?t=16807
2012-06-09 09:58:03.867 SocketTesterNonARC[8271:f803] requestFinished() 1728195448305002263:60:60:websocket,xhr-polling,jsonp-polling,htmlfile,flashsocket
2012-06-09 09:58:03.869 SocketTesterNonARC[8271:f803] sid: 1728195448305002263
2012-06-09 09:58:03.873 SocketTesterNonARC[8271:f803] heartbeatTimeout: 67.000000
2012-06-09 09:58:03.875 SocketTesterNonARC[8271:f803] transports: (
    websocket,
    "xhr-polling",
    "jsonp-polling",
    htmlfile,
    flashsocket
)
2012-06-09 09:58:03.875 SocketTesterNonARC[8271:f803] Opening ws://50.97.85.225:80/socket.io/1/websocket/1728195448305002263
2012-06-09 09:58:09.027 SocketTesterNonARC[8271:f803] ERROR: Connection failed with error ... Read operation timed out
2012-06-09 09:58:09.028 SocketTesterNonARC[8271:f803] onDisconnect()

because you don't have access to the server, try debugging the traffic: http://stackoverflow.com/questions/5751495/debugging-websocket-in-google-chrome

quintet commented 12 years ago

We got that error sometimes but we are getting connected too. We don't think it is a server access issue. Also rather than Read operation timed out error, we are getting null error most of the time. @claaslange are you getting any server logs when xcode returns connection error with null value? You posted the logs when timeout error happens. We are thinking when null error happens the connection request is not getting to the server at all.

Nadavrbn commented 12 years ago

I am also encountering the same issue in my app. I am working with a node.js server and the same error has happened on 3 different machines running the server(1 of the was a local server). It happened while running on a simulator and on an iphone too. I can gain to the server through a web browser without a problem too. It seems to me like the issue is more related to the cocoa-websocket project then this.

Nadavrbn commented 12 years ago

When I ran the server locally I remember having the same error, something with invalid websocket key.

kayleg commented 12 years ago

I was receiving this issue too, then I swapped out the cocoa-websocket with SocketRocket and haven't received it again. cocoa-websocket seems to have issues.

If people would like to try my fork and post back I will be glad to open a pull request.

pkyeck commented 12 years ago

that was on my todo-list anyway ... i'll have a look at socketrocket and will probably switch the two.

Nadavrbn commented 12 years ago

@kayleg I would love it if you could commit your work and post a link back here.

kayleg commented 12 years ago

Sure here it is:

https://github.com/kayleg/socket.IO-objc

Nadavrbn commented 12 years ago

Thanks a lot! So far I haven't had any problems.

taiyangc commented 12 years ago

Seems to have resolved my issue as well. Thanks @kayleg

pkyeck commented 12 years ago

added the changes by kayleg to the master branch

quintet commented 12 years ago

Have you updated non ARC version too?