Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.


---
Expand All @@ -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
Expand Down
27 changes: 15 additions & 12 deletions SocketIO.m
Original file line number Diff line number Diff line change
Expand Up @@ -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%@";
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -291,6 +291,7 @@ - (void) sendEvent:(NSString *)eventName withData:(id)data andAcknowledge:(Socke
if (function) {
packet.ack = @"data";
}
NSLog(@"%@", packet.data);
[self send:packet];
}

Expand Down Expand Up @@ -338,7 +339,7 @@ - (void) send:(SocketIOPacket *)packet
return;
}
DEBUGLOG(@"Prepare to send()");

packet.endpoint = _endpoint;

NSString *req = [packet toString];
if (![_transport isReady]) {
Expand Down Expand Up @@ -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"])
Expand All @@ -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];

Expand Down Expand Up @@ -741,7 +742,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];
}
Expand All @@ -759,8 +761,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];
Expand All @@ -774,7 +776,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);
Expand Down Expand Up @@ -864,7 +866,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
Expand Down Expand Up @@ -1009,7 +1011,8 @@ - (void) connectionDidFinishLoading:(NSURLConnection *)connection
DEBUGLOG(@"VERSION 10x");
_version = V10x;
//...0{"sid":"<sid>","upgrades":[<transports>,...],"pingInterval":<timeHeartbeat>,"pingTimeout":<timeOut>}
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];
Expand Down
6 changes: 3 additions & 3 deletions SocketIOPacket.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
30 changes: 21 additions & 9 deletions SocketIOPacket.m
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ - (id) initWithType:(NSString *)packetType
return self;
}

- (id) initWithTypeIndex:(int)index
- (id) initWithTypeIndex:(NSUInteger)index
{
self = [self init];
if (self) {
Expand All @@ -78,37 +78,49 @@ - (id) dataAsJSON

- (NSString *) toString
{
NSMutableArray *encoded = [NSMutableArray arrayWithObject:[self typeAsNumber]];
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
if ([typeAsNumber intValue] == 2) {
[encoded addObject:@"probe"];
}
}

// 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, @"+"];
Expand All @@ -126,7 +138,7 @@ - (NSNumber *) typeAsNumber
return num;
}

- (NSString *) typeForIndex:(int)index
- (NSString *) typeForIndex:(NSUInteger)index
{
return [_types objectAtIndex:index];
}
Expand All @@ -144,7 +156,7 @@ + (SocketIOPacket *) createPacketWithType:(NSString *)type
}
}

+ (SocketIOPacket *) createPacketWithTypeIndex:(int) type
+ (SocketIOPacket *) createPacketWithTypeIndex:(NSUInteger) type
version:(SocketIOVersion) version
{
switch (version) {
Expand Down
16 changes: 8 additions & 8 deletions SocketIOTransportWebsocket.m
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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];

Expand Down
4 changes: 4 additions & 0 deletions SocketTesterARC.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand All @@ -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; };
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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 */,
);
Expand Down
15 changes: 15 additions & 0 deletions socket.io-objc.podspec
Original file line number Diff line number Diff line change
@@ -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 = { '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' }
spec.source_files = '*.{h,m}'
spec.requires_arc = true
spec.dependency 'SocketRocket'
spec.platforms = { "ios" => "6.0",
"osx" => "10.8" }
end
30 changes: 0 additions & 30 deletions submodules/.gitignore

This file was deleted.

1 change: 0 additions & 1 deletion submodules/socket-rocket
Submodule socket-rocket deleted from 8275ef