From aa14969738f283026d48548e1456a063bf09848d Mon Sep 17 00:00:00 2001 From: Pascal Bihler Date: Thu, 23 Apr 2015 13:02:43 +0200 Subject: [PATCH 1/2] Fix for empty (@"") endpoints. Without, Socket.IO discards the connection. --- SocketIOPacket.m | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/SocketIOPacket.m b/SocketIOPacket.m index 5e5be67..b3fc1f4 100644 --- a/SocketIOPacket.m +++ b/SocketIOPacket.m @@ -82,7 +82,12 @@ - (NSString *) toString NSMutableArray *encoded = [NSMutableArray arrayWithObject:typeAsNumber]; NSNumber *typeNumber = [self typeAsNumber]; - if (!(self.endpoint == nil || [@"/" isEqualToString:self.endpoint]) && [typeNumber intValue] != 6 && [typeNumber intValue] != 2) + + BOOL endpointIsEmpty = ! [self.endpoint length]; + BOOL endpointIsRoot = [@"/" isEqualToString:self.endpoint]; + BOOL endpointIsDefault = endpointIsEmpty || endpointIsRoot; + + if (! endpointIsDefault && [typeNumber intValue] != 6 && [typeNumber intValue] != 2) { [encoded addObject:[self.endpoint stringByAppendingString:@","]]; } From 5d916a0866966b5a6035006bcbded34bb573a74f Mon Sep 17 00:00:00 2001 From: Pascal Bihler Date: Thu, 23 Apr 2015 13:09:09 +0200 Subject: [PATCH 2/2] Refactored type-based if clauses for more code clarity Corresponding comments deprecated? --- SocketIOPacket.m | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/SocketIOPacket.m b/SocketIOPacket.m index b3fc1f4..7eaf43d 100644 --- a/SocketIOPacket.m +++ b/SocketIOPacket.m @@ -81,13 +81,15 @@ - (NSString *) toString NSNumber *typeAsNumber = [self typeAsNumber]; NSMutableArray *encoded = [NSMutableArray arrayWithObject:typeAsNumber]; - NSNumber *typeNumber = [self typeAsNumber]; + //BOOL typeIsDisconnect = [typeAsNumber intValue] == 0; + BOOL typeIsHeartbeat = [typeAsNumber intValue] == 2; + BOOL typeIsAck = [typeAsNumber intValue] == 6; BOOL endpointIsEmpty = ! [self.endpoint length]; BOOL endpointIsRoot = [@"/" isEqualToString:self.endpoint]; BOOL endpointIsDefault = endpointIsEmpty || endpointIsRoot; - if (! endpointIsDefault && [typeNumber intValue] != 6 && [typeNumber intValue] != 2) + if (! (endpointIsDefault || typeIsHeartbeat || typeIsAck)) { [encoded addObject:[self.endpoint stringByAppendingString:@","]]; } @@ -102,19 +104,19 @@ - (NSString *) toString } } else { // Engine.IO 1.0 expects payload with the ping packet - if ([typeAsNumber intValue] == 2) { + if (typeIsHeartbeat) { [encoded addObject:@"probe"]; } } // Do not write pid for acknowledgements - if ([typeNumber intValue] != 6) { + if (! typeIsAck) { [encoded addObject:pIdL]; } // Add the end point for the namespace to be used, as long as it is not // an ACK, heartbeat, or disconnect packet - /*if ([type intValue] != 6 && [type intValue] != 2 && [type intValue] != 0) { + /*if (! (typeIsHeartbeat || typeIsAck || typeIsDisconnect)) { [encoded addObject:endpoint]; } else { @@ -125,7 +127,7 @@ - (NSString *) toString { NSString *ackpId = @""; // This is an acknowledgement packet, so, prepend the ack pid to the data - if ([typeNumber intValue] == 6) + if (typeIsAck) { if( !([self isKindOfClass:[SocketIOPacketV10x class]]) ) ackpId = [NSString stringWithFormat:@":%@%@", pIdL, @"+"];