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

client not handshaken client should reconnect

Open ngzhongcai-zz opened this issue 11 years ago • 5 comments

#69 #77

May be related to above two, but I am opening another ticket here anyways. At the back, I am running multiple socket.io servers with Haproxy in the front. If I were to forcefully pull the plug on one of the socket.io servers, Haproxy will route connection to another socket.io server.

Issue1: SocketDidDisconnect is not fired Issue2: I keep getting client not handshaken client should reconnect on the sio server Issue3: On iOS side, I get a string of "onData 7:::1+0".

So I tried to modify the code by "[self disconnectForced]" at "onData 7:::1+0", and then reconnecting again. Fresh connection is made, but I am still getting the barrage of "client not handshaken client should reconnect", in addition to the fresh connection made.

Any ideas?

ngzhongcai-zz avatar Aug 14 '13 07:08 ngzhongcai-zz

case 7: { DEBUGLOG(@"error"); if([packet.data isEqualToString:@"1+0"]) { [self disconnectForced]; } }

ngzhongcai-zz avatar Aug 14 '13 08:08 ngzhongcai-zz

But still getting a string of "warn - client not handshaken client should reconnect" on server side

ngzhongcai-zz avatar Aug 14 '13 08:08 ngzhongcai-zz

did some time profiling, "checkAndStartPoll" from SocketIOTransportXHR was still firing after "[self disconnectForced]"

ngzhongcai-zz avatar Aug 14 '13 08:08 ngzhongcai-zz

It's quite dirty... I made 2 modifications.

  1. In SocketIO.m, I added "case 7: { DEBUGLOG(@"error"); if([packet.data isEqualToString:@"1+0"]) { [self disconnectForced]; } }" to "onData:(NSString *)data"
  2. In SocketIOTransportXHR.m, I added "if(![message isEqualToString:@"7:::1+0"]) { [self checkAndStartPoll]; }" to "connectionDidFinishLoading:(NSURLConnection *)connection"

This stops it client from bombarding the server with "client not handshaken client should reconnect". But hoping for more cleaner fix?

ngzhongcai-zz avatar Aug 14 '13 10:08 ngzhongcai-zz

I'm hosting on Heroku so I have to use long polling, and I ran into the same issue. I think your fix is as clean as it can be without significantly modifying things.

I wanted to automatically reconnect in this situation so I added this to SocketIO.m:

-(void) reconnect {
    [self connectToHost:self.host onPort:self.port];
}

and call it after disconnectForced:

if([packet.data isEqualToString:@"1+0"]) {
    [self disconnectForced];
    [self reconnect];
}

tybro0103 avatar Aug 30 '13 16:08 tybro0103