socket.IO-objc icon indicating copy to clipboard operation
socket.IO-objc copied to clipboard

disconnectedWithError (SocketIOError error -4.)

Open MobDeveloper opened this issue 12 years ago • 16 comments

Hi..

Stuck at the first point..not able to make connection ..

I am using Node version : 0.10.3 and Socket.io version : 0.9.4.

XCode Log is as below :

didReceiveResponse() 200 connectionDidFinishLoading() 16734788022033017528:15:25:websocket,htmlfile,xhr-polling,jsonp-polling sid: 16734788022033017528 heartbeatTimeout: 22.000000 transports: ( websocket, htmlfile, "xhr-polling", "jsonp-polling" ) websocket supported -> using it now onDisconnect() disconnectedWithError : Error Domain=SocketIOError Code=-4 "The operation couldn’t be completed. (SocketIOError error -4.)"

Thanks in advance !

MobDeveloper avatar Apr 12 '13 13:04 MobDeveloper

Same here. It connects, handshake, then onDisconnect() is called. I don't get the

"disconnectedWithError : Error Domain=SocketIOError Code=-4 "The operation couldn’t be completed. (SocketIOError error -4.)"

in my log tho.

EDIT: It works not, I reject WebSocket and used Long Polling. I think it's because the iPhone simulator was not over wifi but was on iPhone hotspot so it doesn't work with WebSocket?

vandutran avatar Apr 18 '13 20:04 vandutran

I've got the same issue, I just implemented a server-side socket for Facebook and I get this error after my log to Facebook.

kevinvavelin avatar Apr 24 '13 20:04 kevinvavelin

No idea here ? I get this error in random way now :/ I don't know how this happened. How can I avoid this error ? I run socket.io on my device so I don't think this is a problem with the simulator...

kevinvavelin avatar May 01 '13 20:05 kevinvavelin

Have you tried not using WebSocket and use Long Polling instead? I commented out the if statement for WebSocket and has the Long Polling as the first option.

vandutran avatar May 02 '13 13:05 vandutran

And how you did that ? I searched but never found :/ I think that my problem comes from the Facebook token who is really too long for the socket so I decided to not send it in the same event and send it with another event. It's really bad but I don't have my socket closed like that :)

kevinvavelin avatar May 02 '13 13:05 kevinvavelin

In xcode search for the string "using it now" in the project codes. It'll bring you to the code:

    // get transports
    NSString *t = [data objectAtIndex:3];
    NSArray *transports = [t componentsSeparatedByString:@","];
    DEBUGLOG(@"transports: %@", transports);

    /*if ([transports indexOfObject:@"websocket"] != NSNotFound) {
        DEBUGLOG(@"websocket supported -> using it now");
        _transport = [[SocketIOTransportWebsocket alloc] initWithDelegate:self];
    }
    else*/ if ([transports indexOfObject:@"xhr-polling"] != NSNotFound) {
        DEBUGLOG(@"xhr polling supported -> using it now");
        _transport = [[SocketIOTransportXHR alloc] initWithDelegate:self];
    }
    else {
        DEBUGLOG(@"no transport found that is supported :( -> fail");
        connectionFailed = true;
        error = [NSError errorWithDomain:SocketIOError
                                    code:SocketIOTransportsNotSupported
                                userInfo:nil];
    }
}

vandutran avatar May 02 '13 14:05 vandutran

Done but now, I don't have what I'm supposed to get from my socket. Now I get my html instead of my socket. To prevent deconnexion from Facebook connexion, I used sendEvent:withData:andAcknowledge: method, and with long polling I get a serie of error, start/reset message in log. I don't know what to do actually. Why this websocket closed so suddenly ?

Edit: Deconnexion appears even if I used sendEvent:withData:andAcknowledge: , I use the socket on my website so it works really great. I can't understand why I get a deconnexion here :/

kevinvavelin avatar May 03 '13 12:05 kevinvavelin

With more investigation it looks like the problem comes from SRWebSocket where NSInputStream get NSStreamEventEndEncountered without any reason, or I don't understand the function _innerPumpScanner, it looks good but how we reach the end of NSInputStream if the connection is not close ?

kevinvavelin avatar May 04 '13 22:05 kevinvavelin

Any luck figuring this one out ?

mcastilho avatar Oct 23 '13 22:10 mcastilho

I'm getting this same exact issue. Connection, handshake, then onDisconnect and SocketIOError -4. Also, it happens randomly. Weirdly, sometimes it works, and sometimes it doesn't and I have absolutely no idea why.

Anyone else have any idea why this isn't working?

entire avatar Dec 10 '13 07:12 entire

Does anyone get it working? I've got the same error and normally it happens when we connect to internet via a Captive Portal. The long-polling technique isn't working as expected for me.

Sophally avatar May 24 '14 10:05 Sophally

I've got my problem solved by just changing the port to 443. It seems that there are firewall or anti-virus eats my packet on port 80. The port itself is not closed but the packet from websocket cannot bypass this port.

Sophally avatar May 27 '14 11:05 Sophally

I am getting same error. After connecting to host it gets disconnected. Anyone got this working? or any alternative to SocketTesterARC??

Any updates to this? Same exact issue on my end.

mamaral avatar Jan 04 '16 18:01 mamaral

Slight progress, not sure how relevant it is:

Looking at line 757 of SocketIO.m:

if (webSocketTransportClass != nil && [transports indexOfObject:@"websocket"] != NSNotFound) {

I noticed that if I printed out transports, my array of transports included the ["websocket"] rather than "websocket". I changed that line of code to match what I have below, and I seem to be at least making progress to where I was previously. Will share more if I find anything else out.

if (webSocketTransportClass != nil && [transports indexOfObject:@"[\"websocket\"]"] != NSNotFound) {

mamaral avatar Jan 04 '16 18:01 mamaral

The information appears to not be either formatted or parsed correctly:

In SocketIO.m:

DEBUGLOG(@"connectionDidFinishLoading() %@", responseString);
NSArray *data = [responseString componentsSeparatedByString:@":"];

responseString is: 97:0{"sid":"xxxxxxxxxxxxxxxxxxxx","upgrades":["websocket"],"pingInterval":25000,"pingTimeout":60000}

And data is

(
97,
0{"sid",
"CVmcruBxFAgpV3pMAAAA","upgrades",
["websocket"],"pingInterval",
25000,"pingTimeout",
60000}
)

That seems wrong to me, but I'm definitely no expert... Shortly after that code we grab the _heartbeatTimeout, which when you take the above mangled array ends up as 0{"sid", which is obviously formatted wrong and thus connectionFailed is true:

_heartbeatTimeout = [[data objectAtIndex:1] floatValue];
 if (_heartbeatTimeout == 0.0) {
    // couldn't find float value -> fail
    connectionFailed = true;
}

..and then a few lines below that when it tries to parse the transports it gets that all wrong..

Could some of this be due to the implementation here: https://github.com/pkyeck/socket.IO-objc/blob/master/SocketIO.m#L706 ?

mamaral avatar Jan 04 '16 22:01 mamaral