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

Commit db302ef

Browse files
committed
handshake response data check updated. fixes #62.
1 parent 407d74c commit db302ef

File tree

1 file changed

+44
-43
lines changed

1 file changed

+44
-43
lines changed

SocketIO.m

Lines changed: 44 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -635,56 +635,57 @@ - (void) connectionDidFinishLoading:(NSURLConnection *)connection
635635

636636
// check each returned value (thanks for the input https://github.com/taiyangc)
637637
BOOL connectionFailed = false;
638+
NSError* error;
638639

639640
_sid = [data objectAtIndex:0];
640641
if ([_sid length] < 1 || [data count] < 4) {
641642
// did not receive valid data, possibly missing a useSecure?
642643
connectionFailed = true;
643644
}
644-
645-
// check SID
646-
DEBUGLOG(@"sid: %@", _sid);
647-
NSString *regex = @"[^0-9]";
648-
NSPredicate *regexTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
649-
if ([_sid rangeOfString:@"error"].location != NSNotFound || [regexTest evaluateWithObject:_sid]) {
650-
[self connectToHost:_host onPort:_port withParams:_params withNamespace:_endpoint];
651-
return;
652-
}
653-
654-
// check heartbeat timeout
655-
_heartbeatTimeout = [[data objectAtIndex:1] floatValue];
656-
if (_heartbeatTimeout == 0.0) {
657-
// couldn't find float value -> fail
658-
connectionFailed = true;
659-
}
660-
else {
661-
// add small buffer of 7sec (magic xD)
662-
_heartbeatTimeout += 7.0;
663-
}
664-
DEBUGLOG(@"heartbeatTimeout: %f", _heartbeatTimeout);
665-
666-
// index 2 => connection timeout
667-
668-
// get transports
669-
NSString *t = [data objectAtIndex:3];
670-
NSArray *transports = [t componentsSeparatedByString:@","];
671-
DEBUGLOG(@"transports: %@", transports);
672-
673-
NSError* error;
674-
if ([transports indexOfObject:@"websocket"] != NSNotFound) {
675-
DEBUGLOG(@"websocket supported -> using it now");
676-
_transport = [[SocketIOTransportWebsocket alloc] initWithDelegate:self];
677-
}
678-
else if ([transports indexOfObject:@"xhr-polling"] != NSNotFound) {
679-
DEBUGLOG(@"xhr polling supported -> using it now");
680-
_transport = [[SocketIOTransportXHR alloc] initWithDelegate:self];
681-
}
682645
else {
683-
DEBUGLOG(@"no transport found that is supported :( -> fail");
684-
connectionFailed = true;
685-
error = [NSError errorWithDomain:SocketIOError
686-
code:SocketIOTransportsNotSupported
687-
userInfo:nil];
646+
// check SID
647+
DEBUGLOG(@"sid: %@", _sid);
648+
NSString *regex = @"[^0-9]";
649+
NSPredicate *regexTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
650+
if ([_sid rangeOfString:@"error"].location != NSNotFound || [regexTest evaluateWithObject:_sid]) {
651+
[self connectToHost:_host onPort:_port withParams:_params withNamespace:_endpoint];
652+
return;
653+
}
654+
655+
// check heartbeat timeout
656+
_heartbeatTimeout = [[data objectAtIndex:1] floatValue];
657+
if (_heartbeatTimeout == 0.0) {
658+
// couldn't find float value -> fail
659+
connectionFailed = true;
660+
}
661+
else {
662+
// add small buffer of 7sec (magic xD)
663+
_heartbeatTimeout += 7.0;
664+
}
665+
DEBUGLOG(@"heartbeatTimeout: %f", _heartbeatTimeout);
666+
667+
// index 2 => connection timeout
668+
669+
// get transports
670+
NSString *t = [data objectAtIndex:3];
671+
NSArray *transports = [t componentsSeparatedByString:@","];
672+
DEBUGLOG(@"transports: %@", transports);
673+
674+
if ([transports indexOfObject:@"websocket"] != NSNotFound) {
675+
DEBUGLOG(@"websocket supported -> using it now");
676+
_transport = [[SocketIOTransportWebsocket alloc] initWithDelegate:self];
677+
}
678+
else if ([transports indexOfObject:@"xhr-polling"] != NSNotFound) {
679+
DEBUGLOG(@"xhr polling supported -> using it now");
680+
_transport = [[SocketIOTransportXHR alloc] initWithDelegate:self];
681+
}
682+
else {
683+
DEBUGLOG(@"no transport found that is supported :( -> fail");
684+
connectionFailed = true;
685+
error = [NSError errorWithDomain:SocketIOError
686+
code:SocketIOTransportsNotSupported
687+
userInfo:nil];
688+
}
688689
}
689690

690691
// if connection didn't return the values we need -> fail

0 commit comments

Comments
 (0)