From 81b4c203cdf3d4662ef6deeb6b5fb8f3fc959c08 Mon Sep 17 00:00:00 2001 From: Bilal Demirci Date: Tue, 16 Dec 2014 15:50:17 +0200 Subject: [PATCH 1/8] if response has not "{" character, code was crashed. --- SocketIO.m | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/SocketIO.m b/SocketIO.m index 6cfc636..a2497f8 100755 --- a/SocketIO.m +++ b/SocketIO.m @@ -1009,7 +1009,8 @@ - (void) connectionDidFinishLoading:(NSURLConnection *)connection DEBUGLOG(@"VERSION 10x"); _version = V10x; //...0{"sid":"","upgrades":[,...],"pingInterval":,"pingTimeout":} - responseString = [responseString substringFromIndex:[responseString rangeOfString:@"{"].location]; + if([responseString rangeOfString:@"{"].location != NSNotFound) + responseString = [responseString substringFromIndex:[responseString rangeOfString:@"{"].location]; DEBUGLOG(@"Response %@", responseString); connectionFailed = true; NSData *utf8Data = [responseString dataUsingEncoding:NSUTF8StringEncoding]; From 1f0bdff84384bed7e41fcd5c1c8118e68f6927cc Mon Sep 17 00:00:00 2001 From: Pascal Bihler Date: Wed, 11 Feb 2015 17:06:55 +0100 Subject: [PATCH 2/8] Added payload to ping packet as required by engine.io --- SocketIOPacket.m | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/SocketIOPacket.m b/SocketIOPacket.m index cdac17c..c31cce8 100644 --- a/SocketIOPacket.m +++ b/SocketIOPacket.m @@ -78,7 +78,8 @@ - (id) dataAsJSON - (NSString *) toString { - NSMutableArray *encoded = [NSMutableArray arrayWithObject:[self typeAsNumber]]; + NSNumber *typeAsNumber = [self typeAsNumber]; + NSMutableArray *encoded = [NSMutableArray arrayWithObject:typeAsNumber]; NSString *pIdL = self.pId != nil ? self.pId : @""; @@ -88,6 +89,11 @@ - (NSString *) toString { pIdL = [pIdL stringByAppendingString:@"+"]; } + } else { + // Engine.IO 1.0 expects payload with the ping packet + if ([typeAsNumber intValue] == 2) { + [encoded addObject:@"probe"]; + } } // Do not write pid for acknowledgements From 22baa68a0b9eb2b92e875f991b6b82a5b92890d3 Mon Sep 17 00:00:00 2001 From: Francois Payette Date: Mon, 23 Feb 2015 09:23:08 -0500 Subject: [PATCH 3/8] Update README.md --- README.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 20b9785..16b34b2 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -**This fork supports some socket.io v1.0 features, (no binary support yet). Many thanks to francoisTemasys who did most of the heavy lifting; this is a fork of a fork. v0.9.x compatibility is generally maintained. +**This fork supports some socket.io v1.x features, (no binary support yet). Many thanks to francoisTemasys who did most of the heavy lifting; this is a fork of a fork. v0.9.x compatibility is generally maintained. --- @@ -15,8 +15,7 @@ ## Requirements -As of version 0.4, this library requires at least OS X 10.7 or iOS 5.0. -Because of this, we were able to remove the external JSON frameworks in v0.5 and only rely on iOS' own `NSJSONSerialization`. +This library requires at least OS X 10.7 or iOS 5.0. ## Usage From 90cbfcfaa88e3459468223d0b496b434f0a5c933 Mon Sep 17 00:00:00 2001 From: Francois Payette Date: Thu, 26 Feb 2015 16:29:07 -0500 Subject: [PATCH 4/8] add podspec, thanks to toblerpwn for sample --- SocketTesterARC.xcodeproj/project.pbxproj | 4 ++++ socket.io-objc.podspec | 15 +++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 socket.io-objc.podspec diff --git a/SocketTesterARC.xcodeproj/project.pbxproj b/SocketTesterARC.xcodeproj/project.pbxproj index e8e4616..9bb00cd 100644 --- a/SocketTesterARC.xcodeproj/project.pbxproj +++ b/SocketTesterARC.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 00DC61D01A9FC62100136DE1 /* socket.io-objc.podspec in Resources */ = {isa = PBXBuildFile; fileRef = 00DC61CF1A9FC62100136DE1 /* socket.io-objc.podspec */; }; 4A444FA11589E28800B44ABB /* libicucore.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 4A444FA01589E28800B44ABB /* libicucore.dylib */; }; 4A444FA31589E29500B44ABB /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4A444FA21589E29500B44ABB /* Security.framework */; }; 4A4453811589EE9100B44ABB /* base64.c in Sources */ = {isa = PBXBuildFile; fileRef = 4A44537A1589EE9100B44ABB /* base64.c */; }; @@ -31,6 +32,7 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 00DC61CF1A9FC62100136DE1 /* socket.io-objc.podspec */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "socket.io-objc.podspec"; sourceTree = SOURCE_ROOT; }; 4A444FA01589E28800B44ABB /* libicucore.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libicucore.dylib; path = usr/lib/libicucore.dylib; sourceTree = SDKROOT; }; 4A444FA21589E29500B44ABB /* Security.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Security.framework; path = System/Library/Frameworks/Security.framework; sourceTree = SDKROOT; }; 4A44537A1589EE9100B44ABB /* base64.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = base64.c; path = "submodules/socket-rocket/SocketRocket/base64.c"; sourceTree = SOURCE_ROOT; }; @@ -146,6 +148,7 @@ 4ADCCBC615790DEC0022990C /* SocketIO.h */, 4ADCCBC715790DEC0022990C /* SocketIO.m */, 4AD96DF21680853E00D9E42D /* SocketIOPacket.h */, + 00DC61CF1A9FC62100136DE1 /* socket.io-objc.podspec */, 4AD96DF31680853E00D9E42D /* SocketIOPacket.m */, C9E391A015E2A1B00004693A /* SocketIOJSONSerialization.h */, C9E391A115E2A1B00004693A /* SocketIOJSONSerialization.m */, @@ -221,6 +224,7 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( + 00DC61D01A9FC62100136DE1 /* socket.io-objc.podspec in Resources */, 4ADCCBAC15790D760022990C /* InfoPlist.strings in Resources */, 4ADCCBB815790D760022990C /* ViewController.xib in Resources */, ); diff --git a/socket.io-objc.podspec b/socket.io-objc.podspec new file mode 100644 index 0000000..a6d11ea --- /dev/null +++ b/socket.io-objc.podspec @@ -0,0 +1,15 @@ +Pod::Spec.new do |spec| +spec.name = 'socket.io-objc' +spec.version = '0.6.4' +spec.license = 'MIT' +spec.homepage = 'https://github.com/francoisp/socket.IO-objc/' +spec.authors = { 'Francois Payette' => 'francoisp@netmosphere.net' } +spec.summary = 'Socket.io 1.x client for Objective-C projects., with backward 0.9 compatibility' +spec.description = "Interface to communicate between Objective C and Socket.IO with the help of websockets. Originally based on fpotter's socketio-cocoa and uses square's SocketRocket.\n" +spec.source = { :git => 'https://github.com/francoisp/socket.IO-objc.git' } +spec.source_files = '*.{h,m}' +spec.requires_arc = true +spec.dependency 'SocketRocket' +spec.platforms = { "ios" => "6.0", +"osx" => "10.8" } +end \ No newline at end of file From 9d5339af2719790c35187474ffa9e6a77a9042e6 Mon Sep 17 00:00:00 2001 From: Pascal Bihler Date: Thu, 12 Feb 2015 00:23:08 +0100 Subject: [PATCH 5/8] Small fixes for 64bit --- SocketIO.m | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/SocketIO.m b/SocketIO.m index a2497f8..d6d9e94 100755 --- a/SocketIO.m +++ b/SocketIO.m @@ -135,7 +135,7 @@ - (void) connectToHost:(NSString *)host // do handshake via HTTP request NSString *protocol = _useSecure ? @"https" : @"http"; - NSString *port = _port ? [NSString stringWithFormat:@":%d", _port] : @""; + NSString *port = _port ? [NSString stringWithFormat:@":%ld", (long)_port] : @""; NSTimeInterval time = [[NSDate date] timeIntervalSince1970] * 1000; NSString *handshakeUrl = [NSString stringWithFormat:kHandshakeURL, protocol, _host, port, kResourceName,kTransportPolling, time, query]; //@"%@://%@%@/%@/1/?t=%.0f%@"; @@ -185,7 +185,7 @@ - (void) disconnect - (void) disconnectForced { NSString *protocol = [self useSecure] ? @"https" : @"http"; - NSString *port = _port ? [NSString stringWithFormat:@":%d", _port] : @""; + NSString *port = _port ? [NSString stringWithFormat:@":%ld", (long)_port] : @""; NSString *urlString = [NSString stringWithFormat:kForceDisconnectURL, protocol, _host, port, kResourceName, _sid]; NSURL *url = [NSURL URLWithString:urlString]; DEBUGLOG(@"Force disconnect at: %@", urlString); @@ -741,7 +741,8 @@ - (void) onData:(NSString *)data packet.args = [parsedData subarrayWithRange:NSMakeRange(1, parsedData.count-1)]; if([packet.name isEqualToString:@"message"]) { - packet.data = packet.args[0]; + // data is specified as NSString, so rewrap it... + packet.data = [SocketIOJSONSerialization JSONStringFromObject:packet.args[0] error:nil]; if ([_delegate respondsToSelector:@selector(socketIO:didReceiveMessage:)]) { [_delegate socketIO:self didReceiveMessage:packet]; } From 405cbdbcc47bb92613956b4417d977f44c415e6b Mon Sep 17 00:00:00 2001 From: Pascal Bihler Date: Wed, 18 Mar 2015 13:47:45 +0100 Subject: [PATCH 6/8] Updated SocketRocket submodule commit --- submodules/socket-rocket | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/submodules/socket-rocket b/submodules/socket-rocket index 8275ef3..a2dd92a 160000 --- a/submodules/socket-rocket +++ b/submodules/socket-rocket @@ -1 +1 @@ -Subproject commit 8275ef3b15cebd99b1815840c55f4e07f96bf862 +Subproject commit a2dd92a13b42e14fee0c93253e464121c1de67d5 From 2f13a44ae18135a80bdc70a434a208ddc47e83ce Mon Sep 17 00:00:00 2001 From: Pascal Bihler Date: Wed, 18 Mar 2015 14:10:39 +0100 Subject: [PATCH 7/8] More fixes to remove warnings when building with 64bit --- SocketIO.m | 8 ++++---- SocketIOPacket.h | 6 +++--- SocketIOPacket.m | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/SocketIO.m b/SocketIO.m index d6d9e94..d9ea707 100755 --- a/SocketIO.m +++ b/SocketIO.m @@ -760,8 +760,8 @@ - (void) onData:(NSString *)data { if (ack > 0) { - int ackId = ack; - DEBUGLOG(@"ack id found: %d", ackId); + NSUInteger ackId = ack; + DEBUGLOG(@"ack id found: %d", (unsigned int)ackId); NSString *argsStr = [packet.data substringFromIndex:1 ]; argsStr = [argsStr substringToIndex:argsStr.length-1]; @@ -775,7 +775,7 @@ - (void) onData:(NSString *)data } // get selector for ackId - NSString *key = [NSString stringWithFormat:@"%d", ackId]; + NSString *key = [NSString stringWithFormat:@"%d", (unsigned int)ackId]; SocketIOCallback callbackFunction = [_acks objectForKey:key]; if (callbackFunction != nil) { callbackFunction(argsData); @@ -865,7 +865,7 @@ - (void) connection:(NSURLConnection *)connection didReceiveResponse:(NSURLRespo // check for server status code (http://gigliwood.com/weblog/Cocoa/Q__When_is_an_conne.html) if ([response respondsToSelector:@selector(statusCode)]) { NSInteger statusCode = [((NSHTTPURLResponse *)response) statusCode]; - DEBUGLOG(@"didReceiveResponse() %i", statusCode); + DEBUGLOG(@"didReceiveResponse() %i", (int)statusCode); if (statusCode >= 400) { // stop connecting; no more delegate messages diff --git a/SocketIOPacket.h b/SocketIOPacket.h index 8fcfafe..b13be07 100644 --- a/SocketIOPacket.h +++ b/SocketIOPacket.h @@ -45,15 +45,15 @@ @property (nonatomic, copy) NSArray *args; - (id) initWithType:(NSString *)packetType; -- (id) initWithTypeIndex:(int)index; +- (id) initWithTypeIndex:(NSUInteger)index; - (id) dataAsJSON; - (NSString *) toString; - (NSNumber *) typeAsNumber; -- (NSString *) typeForIndex:(int)index; +- (NSString *) typeForIndex:(NSUInteger)index; + (SocketIOPacket *) createPacketWithType:(NSString *)type version:(SocketIOVersion) version; -+ (SocketIOPacket *) createPacketWithTypeIndex:(int) type ++ (SocketIOPacket *) createPacketWithTypeIndex:(NSUInteger) type version:(SocketIOVersion) version; @end diff --git a/SocketIOPacket.m b/SocketIOPacket.m index c31cce8..eece271 100644 --- a/SocketIOPacket.m +++ b/SocketIOPacket.m @@ -55,7 +55,7 @@ - (id) initWithType:(NSString *)packetType return self; } -- (id) initWithTypeIndex:(int)index +- (id) initWithTypeIndex:(NSUInteger)index { self = [self init]; if (self) { @@ -132,7 +132,7 @@ - (NSNumber *) typeAsNumber return num; } -- (NSString *) typeForIndex:(int)index +- (NSString *) typeForIndex:(NSUInteger)index { return [_types objectAtIndex:index]; } @@ -150,7 +150,7 @@ + (SocketIOPacket *) createPacketWithType:(NSString *)type } } -+ (SocketIOPacket *) createPacketWithTypeIndex:(int) type ++ (SocketIOPacket *) createPacketWithTypeIndex:(NSUInteger) type version:(SocketIOVersion) version { switch (version) { From 102b36bcb4f381bb490ea963d0648b193c15ec09 Mon Sep 17 00:00:00 2001 From: Francois Payette Date: Tue, 24 Mar 2015 17:46:55 -0400 Subject: [PATCH 8/8] changes suggested by louis49 to support namespace --- SocketIO.m | 9 +++++---- SocketIOPacket.m | 16 +++++++++++----- SocketIOTransportWebsocket.m | 16 ++++++++-------- socket.io-objc.podspec | 2 +- submodules/.gitignore | 30 ------------------------------ submodules/socket-rocket | 1 - 6 files changed, 25 insertions(+), 49 deletions(-) delete mode 100644 submodules/.gitignore delete mode 160000 submodules/socket-rocket diff --git a/SocketIO.m b/SocketIO.m index d9ea707..0b2c455 100755 --- a/SocketIO.m +++ b/SocketIO.m @@ -291,6 +291,7 @@ - (void) sendEvent:(NSString *)eventName withData:(id)data andAcknowledge:(Socke if (function) { packet.ack = @"data"; } + NSLog(@"%@", packet.data); [self send:packet]; } @@ -338,7 +339,7 @@ - (void) send:(SocketIOPacket *)packet return; } DEBUGLOG(@"Prepare to send()"); - + packet.endpoint = _endpoint; NSString *req = [packet toString]; if (![_transport isReady]) { @@ -686,10 +687,10 @@ - (void) onData:(NSString *)data //?? break; case 2: - { + //Ping->Pong [self sendMessage:[NSString stringWithFormat:@"3:%@", data]]; - } break; + break; case 3: //Pong if([data isEqualToString:@"probe"]) @@ -708,7 +709,7 @@ - (void) onData:(NSString *)data //GET ENDPOINT NSUInteger rendpoint = [packet.data rangeOfString:@"["].location; if(rendpoint == NSNotFound) - packet.endpoint = @""; + packet.endpoint = packet.data; else packet.endpoint = [packet.data substringToIndex:rendpoint]; diff --git a/SocketIOPacket.m b/SocketIOPacket.m index eece271..5e5be67 100644 --- a/SocketIOPacket.m +++ b/SocketIOPacket.m @@ -81,13 +81,19 @@ - (NSString *) toString NSNumber *typeAsNumber = [self typeAsNumber]; NSMutableArray *encoded = [NSMutableArray arrayWithObject:typeAsNumber]; + NSNumber *typeNumber = [self typeAsNumber]; + if (!(self.endpoint == nil || [@"/" isEqualToString:self.endpoint]) && [typeNumber intValue] != 6 && [typeNumber intValue] != 2) + { + [encoded addObject:[self.endpoint stringByAppendingString:@","]]; + } + NSString *pIdL = self.pId != nil ? self.pId : @""; if( !([self isKindOfClass:[SocketIOPacketV10x class]]) ){ if ([self.ack isEqualToString:@"data"]) { - pIdL = [pIdL stringByAppendingString:@"+"]; + //pIdL = [pIdL stringByAppendingString:@"+"]; } } else { // Engine.IO 1.0 expects payload with the ping packet @@ -97,24 +103,24 @@ - (NSString *) toString } // Do not write pid for acknowledgements - if ([type intValue] != 6) { + if ([typeNumber intValue] != 6) { [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 ([type intValue] != 6 && [type intValue] != 2 && [type intValue] != 0) { [encoded addObject:endpoint]; } else { [encoded addObject:@""]; - } + }*/ if (data != nil) { NSString *ackpId = @""; // This is an acknowledgement packet, so, prepend the ack pid to the data - if ([type intValue] == 6) + if ([typeNumber intValue] == 6) { if( !([self isKindOfClass:[SocketIOPacketV10x class]]) ) ackpId = [NSString stringWithFormat:@":%@%@", pIdL, @"+"]; diff --git a/SocketIOTransportWebsocket.m b/SocketIOTransportWebsocket.m index c88c2b9..afd0f11 100644 --- a/SocketIOTransportWebsocket.m +++ b/SocketIOTransportWebsocket.m @@ -29,10 +29,10 @@ #define DEBUGLOG(...) #endif -static NSString* kInsecureSocketURL = @"ws://%@/socket.io/1/websocket/%@%@"; -static NSString* kSecureSocketURL = @"wss://%@/socket.io/1/websocket/%@%@"; -static NSString* kInsecureSocketPortURL = @"ws://%@:%d/socket.io/1/websocket/%@%@"; -static NSString* kSecureSocketPortURL = @"wss://%@:%d/socket.io/1/websocket/%@%@"; +static NSString* kInsecureSocketURL = @"ws://%@/socket.io/1/websocket/%@"; +static NSString* kSecureSocketURL = @"wss://%@/socket.io/1/websocket/%@"; +static NSString* kInsecureSocketPortURL = @"ws://%@:%d/socket.io/1/websocket/%@"; +static NSString* kSecureSocketPortURL = @"wss://%@:%d/socket.io/1/websocket/%@"; @implementation SocketIOTransportWebsocket @@ -62,17 +62,17 @@ - (void) openUsing:(SocketIOVersion)version { NSString *urlStr; NSString *format; - NSString *addOnVersion = @""; + NSString *addOnVersion = delegate.sid;; if(version == V10x) - addOnVersion = @"?EIO=2&transport=websocket&sid="; + addOnVersion = [NSString stringWithFormat:@"?EIO=2&transport=websocket&sid=%@", delegate.sid]; if (delegate.port) { format = delegate.useSecure ? kSecureSocketPortURL : kInsecureSocketPortURL; - urlStr = [NSString stringWithFormat:format, delegate.host, delegate.port, addOnVersion, delegate.sid]; + urlStr = [NSString stringWithFormat:format, delegate.host, delegate.port, addOnVersion, delegate.sid, addOnVersion]; } else { format = delegate.useSecure ? kSecureSocketURL : kInsecureSocketURL; - urlStr = [NSString stringWithFormat:format, delegate.host,addOnVersion, delegate.sid]; + urlStr = [NSString stringWithFormat:format, delegate.host,addOnVersion, delegate.sid, addOnVersion]; } NSURL *url = [NSURL URLWithString:urlStr]; diff --git a/socket.io-objc.podspec b/socket.io-objc.podspec index a6d11ea..abcf9e3 100644 --- a/socket.io-objc.podspec +++ b/socket.io-objc.podspec @@ -3,7 +3,7 @@ spec.name = 'socket.io-objc' spec.version = '0.6.4' spec.license = 'MIT' spec.homepage = 'https://github.com/francoisp/socket.IO-objc/' -spec.authors = { 'Francois Payette' => 'francoisp@netmosphere.net' } +spec.authors = { 'Philipp Kyeck' => 'philipp@beta-interactive.de' } spec.summary = 'Socket.io 1.x client for Objective-C projects., with backward 0.9 compatibility' spec.description = "Interface to communicate between Objective C and Socket.IO with the help of websockets. Originally based on fpotter's socketio-cocoa and uses square's SocketRocket.\n" spec.source = { :git => 'https://github.com/francoisp/socket.IO-objc.git' } diff --git a/submodules/.gitignore b/submodules/.gitignore deleted file mode 100644 index 08b418a..0000000 --- a/submodules/.gitignore +++ /dev/null @@ -1,30 +0,0 @@ -# xcode noise -build/* -build -*.pbxuser -*.mode1v3 -*.mode2v3 -*.perspectivev3 -*.tmproj -*/*.pbxuser -*/*.mode1v3 -*/*.mode2v3 -*/*.perspectivev3 -*/*.tmproj -Build -Products -xcuserdata -xcuserdata/* -project.xcworkspace -project.xcworkspace/* -*/project.xcworkspace -*/project.xcworkspace/* -*/xcuserdata -DerivedData - -# osx noise -.DS_Store -profile - -# vim noise -*.swp diff --git a/submodules/socket-rocket b/submodules/socket-rocket deleted file mode 160000 index a2dd92a..0000000 --- a/submodules/socket-rocket +++ /dev/null @@ -1 +0,0 @@ -Subproject commit a2dd92a13b42e14fee0c93253e464121c1de67d5