Skip to content
This repository has been archived by the owner on May 14, 2024. It is now read-only.

disconnectedWithError (SocketIOError error -4.) #95

Open
MobDeveloper opened this issue Apr 12, 2013 · 16 comments
Open

disconnectedWithError (SocketIOError error -4.) #95

MobDeveloper opened this issue Apr 12, 2013 · 16 comments

Comments

@MobDeveloper
Copy link

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 !

@vandutran
Copy link

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?

@kevinvavelin
Copy link

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
Copy link

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...

@vandutran
Copy link

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.

@kevinvavelin
Copy link

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 :)

@vandutran
Copy link

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];
    }
}

@kevinvavelin
Copy link

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
Copy link

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 ?

@mcastilho
Copy link

Any luck figuring this one out ?

@entire
Copy link

entire commented Dec 10, 2013

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?

@Sophally
Copy link

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
Copy link

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.

@swapnilmishra-globussoft

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

@mamaral
Copy link

mamaral commented Jan 4, 2016

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

@mamaral
Copy link

mamaral commented Jan 4, 2016

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
Copy link

mamaral commented Jan 4, 2016

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 ?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants