From a5a661aa2bb5320c78571979f6bfde0ddbc2ee34 Mon Sep 17 00:00:00 2001 From: Travis Bowers Date: Thu, 2 Apr 2015 09:28:38 -0500 Subject: [PATCH 01/14] Added RocketSockets --- Podfile | 4 +- StompKit.xcodeproj/project.pbxproj | 38 +++++++++++-------- .../xcshareddata/xcschemes/StompKit.xcscheme | 11 +++++- 3 files changed, 36 insertions(+), 17 deletions(-) diff --git a/Podfile b/Podfile index 8fce788..8d69fb6 100644 --- a/Podfile +++ b/Podfile @@ -2,8 +2,10 @@ xcodeproj 'StompKit.xcodeproj' platform :ios, '5.0' + +pod 'SocketRocket', '0.3.1-beta2' pod 'CocoaAsyncSocket', '7.3.2' target 'StompKitTests', :exclusive => true do pod 'Kiwi', '2.2' -end \ No newline at end of file +end diff --git a/StompKit.xcodeproj/project.pbxproj b/StompKit.xcodeproj/project.pbxproj index 4b2c1c8..d6f6021 100644 --- a/StompKit.xcodeproj/project.pbxproj +++ b/StompKit.xcodeproj/project.pbxproj @@ -45,7 +45,7 @@ /* Begin PBXFileReference section */ 37A4F2569A574CA6A0704DA6 /* libPods.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libPods.a; sourceTree = BUILT_PRODUCTS_DIR; }; - 44F558268B504F65BBF4384B /* Pods-StompKitTests.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-StompKitTests.xcconfig"; path = "Pods/Pods-StompKitTests.xcconfig"; sourceTree = ""; }; + 4C55F3E01D49876D5B53EC05 /* Pods.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.debug.xcconfig; path = "Pods/Target Support Files/Pods/Pods.debug.xcconfig"; sourceTree = ""; }; 591868DBFE214F55AB478DA7 /* libPods-StompKitTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-StompKitTests.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 9320F3901816698700FF599F /* Podfile */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Podfile; sourceTree = ""; }; 9320F3911816698700FF599F /* StompKit.podspec */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = StompKit.podspec; sourceTree = ""; }; @@ -62,7 +62,9 @@ 938827ED18056CA2009A1164 /* LICENSE */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = LICENSE; sourceTree = ""; }; 938827EE18056CA2009A1164 /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = README.md; sourceTree = ""; }; 938827F218057877009A1164 /* StompKitTests.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StompKitTests.h; sourceTree = ""; }; - BFE05B97D82D403E8462EDC5 /* Pods.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.xcconfig; path = Pods/Pods.xcconfig; sourceTree = ""; }; + C320AB3F98001F00C6279012 /* Pods-StompKitTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-StompKitTests.release.xcconfig"; path = "Pods/Target Support Files/Pods-StompKitTests/Pods-StompKitTests.release.xcconfig"; sourceTree = ""; }; + D2165909412B23156C9154D2 /* Pods-StompKitTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-StompKitTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-StompKitTests/Pods-StompKitTests.debug.xcconfig"; sourceTree = ""; }; + D4381A627E6D2C175D779A5C /* Pods.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.release.xcconfig; path = "Pods/Target Support Files/Pods/Pods.release.xcconfig"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -90,6 +92,17 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 1C9C6CD9BF6E5DAF68ADBC0D /* Pods */ = { + isa = PBXGroup; + children = ( + 4C55F3E01D49876D5B53EC05 /* Pods.debug.xcconfig */, + D4381A627E6D2C175D779A5C /* Pods.release.xcconfig */, + D2165909412B23156C9154D2 /* Pods-StompKitTests.debug.xcconfig */, + C320AB3F98001F00C6279012 /* Pods-StompKitTests.release.xcconfig */, + ); + name = Pods; + sourceTree = ""; + }; 932BA56F18056C4B00A03257 = { isa = PBXGroup; children = ( @@ -101,8 +114,7 @@ 932BA59118056C4C00A03257 /* StompKitTests */, 932BA57A18056C4B00A03257 /* Frameworks */, 932BA57918056C4B00A03257 /* Products */, - BFE05B97D82D403E8462EDC5 /* Pods.xcconfig */, - 44F558268B504F65BBF4384B /* Pods-StompKitTests.xcconfig */, + 1C9C6CD9BF6E5DAF68ADBC0D /* Pods */, ); sourceTree = ""; }; @@ -203,7 +215,7 @@ 932BA57018056C4B00A03257 /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0500; + LastUpgradeCheck = 0620; ORGANIZATIONNAME = "Jeff Mesnil"; }; buildConfigurationList = 932BA57318056C4B00A03257 /* Build configuration list for PBXProject "StompKit" */; @@ -263,7 +275,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "\"${SRCROOT}/Pods/Pods-StompKitTests-resources.sh\"\n"; + shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-StompKitTests/Pods-StompKitTests-resources.sh\"\n"; showEnvVarsInLog = 0; }; F14EDA9ACA514E238C2E405D /* Check Pods Manifest.lock */ = { @@ -293,7 +305,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "\"${SRCROOT}/Pods/Pods-resources.sh\"\n"; + shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods/Pods-resources.sh\"\n"; showEnvVarsInLog = 0; }; /* End PBXShellScriptBuildPhase section */ @@ -341,7 +353,6 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - ARCHS = "$(ARCHS_STANDARD_INCLUDING_64_BIT)"; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; @@ -379,7 +390,6 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - ARCHS = "$(ARCHS_STANDARD_INCLUDING_64_BIT)"; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; @@ -409,7 +419,7 @@ }; 932BA59C18056C4C00A03257 /* Debug */ = { isa = XCBuildConfiguration; - baseConfigurationReference = BFE05B97D82D403E8462EDC5 /* Pods.xcconfig */; + baseConfigurationReference = 4C55F3E01D49876D5B53EC05 /* Pods.debug.xcconfig */; buildSettings = { DSTROOT = /tmp/StompKit.dst; OTHER_LDFLAGS = "-ObjC"; @@ -420,7 +430,7 @@ }; 932BA59D18056C4C00A03257 /* Release */ = { isa = XCBuildConfiguration; - baseConfigurationReference = BFE05B97D82D403E8462EDC5 /* Pods.xcconfig */; + baseConfigurationReference = D4381A627E6D2C175D779A5C /* Pods.release.xcconfig */; buildSettings = { DSTROOT = /tmp/StompKit.dst; OTHER_LDFLAGS = "-ObjC"; @@ -431,9 +441,8 @@ }; 932BA59F18056C4C00A03257 /* Debug */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 44F558268B504F65BBF4384B /* Pods-StompKitTests.xcconfig */; + baseConfigurationReference = D2165909412B23156C9154D2 /* Pods-StompKitTests.debug.xcconfig */; buildSettings = { - ARCHS = "$(ARCHS_STANDARD_INCLUDING_64_BIT)"; FRAMEWORK_SEARCH_PATHS = ( "$(SDKROOT)/Developer/Library/Frameworks", "$(inherited)", @@ -451,9 +460,8 @@ }; 932BA5A018056C4C00A03257 /* Release */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 44F558268B504F65BBF4384B /* Pods-StompKitTests.xcconfig */; + baseConfigurationReference = C320AB3F98001F00C6279012 /* Pods-StompKitTests.release.xcconfig */; buildSettings = { - ARCHS = "$(ARCHS_STANDARD_INCLUDING_64_BIT)"; FRAMEWORK_SEARCH_PATHS = ( "$(SDKROOT)/Developer/Library/Frameworks", "$(inherited)", diff --git a/StompKit.xcodeproj/xcshareddata/xcschemes/StompKit.xcscheme b/StompKit.xcodeproj/xcshareddata/xcschemes/StompKit.xcscheme index 690f653..aefeedc 100644 --- a/StompKit.xcodeproj/xcshareddata/xcschemes/StompKit.xcscheme +++ b/StompKit.xcodeproj/xcshareddata/xcschemes/StompKit.xcscheme @@ -1,6 +1,6 @@ + + + + From 3ebec61c0ec9f7e642a77951cc6c0cfc245b45aa Mon Sep 17 00:00:00 2001 From: Travis Bowers Date: Thu, 2 Apr 2015 09:59:37 -0500 Subject: [PATCH 02/14] Checkpoint for start of strategy pattern to abstract away GCD Socket use into SKRawSocket --- StompKit.xcodeproj/project.pbxproj | 18 +++++++ StompKit/SKSocket/SKRawSocket.h | 19 +++++++ StompKit/SKSocket/SKRawSocket.m | 85 ++++++++++++++++++++++++++++++ StompKit/SKSocket/SKSocket.h | 34 ++++++++++++ StompKit/StompKit.m | 1 + 5 files changed, 157 insertions(+) create mode 100644 StompKit/SKSocket/SKRawSocket.h create mode 100644 StompKit/SKSocket/SKRawSocket.m create mode 100644 StompKit/SKSocket/SKSocket.h diff --git a/StompKit.xcodeproj/project.pbxproj b/StompKit.xcodeproj/project.pbxproj index d6f6021..e73a678 100644 --- a/StompKit.xcodeproj/project.pbxproj +++ b/StompKit.xcodeproj/project.pbxproj @@ -7,6 +7,8 @@ objects = { /* Begin PBXBuildFile section */ + 1F5B42B21ACD8AF100FABE04 /* SKRawSocket.m in Sources */ = {isa = PBXBuildFile; fileRef = 1F5B42B01ACD8AF100FABE04 /* SKRawSocket.m */; }; + 1F5B42B31ACD8AF100FABE04 /* SKRawSocket.m in Sources */ = {isa = PBXBuildFile; fileRef = 1F5B42B01ACD8AF100FABE04 /* SKRawSocket.m */; }; 6C24B5EB8E0343E483E53CA2 /* libPods.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 37A4F2569A574CA6A0704DA6 /* libPods.a */; }; 932BA57C18056C4B00A03257 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 932BA57B18056C4B00A03257 /* Foundation.framework */; }; 932BA58118056C4B00A03257 /* StompKit.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 932BA58018056C4B00A03257 /* StompKit.h */; }; @@ -44,6 +46,9 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ + 1F5B42AF1ACD8AF100FABE04 /* SKRawSocket.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SKRawSocket.h; sourceTree = ""; }; + 1F5B42B01ACD8AF100FABE04 /* SKRawSocket.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SKRawSocket.m; sourceTree = ""; }; + 1F5B42B11ACD8AF100FABE04 /* SKSocket.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SKSocket.h; sourceTree = ""; }; 37A4F2569A574CA6A0704DA6 /* libPods.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libPods.a; sourceTree = BUILT_PRODUCTS_DIR; }; 4C55F3E01D49876D5B53EC05 /* Pods.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.debug.xcconfig; path = "Pods/Target Support Files/Pods/Pods.debug.xcconfig"; sourceTree = ""; }; 591868DBFE214F55AB478DA7 /* libPods-StompKitTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-StompKitTests.a"; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -103,6 +108,16 @@ name = Pods; sourceTree = ""; }; + 1F5B42AE1ACD8AF100FABE04 /* SKSocket */ = { + isa = PBXGroup; + children = ( + 1F5B42AF1ACD8AF100FABE04 /* SKRawSocket.h */, + 1F5B42B01ACD8AF100FABE04 /* SKRawSocket.m */, + 1F5B42B11ACD8AF100FABE04 /* SKSocket.h */, + ); + path = SKSocket; + sourceTree = ""; + }; 932BA56F18056C4B00A03257 = { isa = PBXGroup; children = ( @@ -144,6 +159,7 @@ children = ( 932BA58018056C4B00A03257 /* StompKit.h */, 932BA58218056C4B00A03257 /* StompKit.m */, + 1F5B42AE1ACD8AF100FABE04 /* SKSocket */, ); path = StompKit; sourceTree = ""; @@ -316,6 +332,7 @@ buildActionMask = 2147483647; files = ( 932BA58318056C4B00A03257 /* StompKit.m in Sources */, + 1F5B42B21ACD8AF100FABE04 /* SKRawSocket.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -324,6 +341,7 @@ buildActionMask = 2147483647; files = ( 932BA59818056C4C00A03257 /* StompKitTests.m in Sources */, + 1F5B42B31ACD8AF100FABE04 /* SKRawSocket.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/StompKit/SKSocket/SKRawSocket.h b/StompKit/SKSocket/SKRawSocket.h new file mode 100644 index 0000000..bccf496 --- /dev/null +++ b/StompKit/SKSocket/SKRawSocket.h @@ -0,0 +1,19 @@ +// +// SKRawSocket.h +// StompKit +// +// Created by Travis Bowers on 4/2/15. +// Copyright (c) 2015 Jeff Mesnil. All rights reserved. +// + +#ifndef StompKit_SKRawSocket_h +#define StompKit_SKRawSocket_h + +#import "SKSocket.h" + +@interface SKRawSocket : NSObject +{ +} +@end + +#endif diff --git a/StompKit/SKSocket/SKRawSocket.m b/StompKit/SKSocket/SKRawSocket.m new file mode 100644 index 0000000..83178e4 --- /dev/null +++ b/StompKit/SKSocket/SKRawSocket.m @@ -0,0 +1,85 @@ +// +// SKRawSocket.m +// StompKit +// +// Created by Travis Bowers on 4/2/15. +// Copyright (c) 2015 Jeff Mesnil. All rights reserved. +// + +#import +#import "SKRawSocket.h" +#import "GCDAsyncSocket.h" + +@interface SKRawSocket() +@property (nonatomic, weak) id delegate; +@property (nonatomic, retain) GCDAsyncSocket *socket; +@end + +@implementation SKRawSocket + +// synthesize properties +@synthesize delegate; +@synthesize socket; + +- (id)initWithDelegate:(id)aDelegate delegateQueue:(dispatch_queue_t)dq { + if((self = [super init])) { + if (aDelegate != nil) { + self.delegate = aDelegate; + + // initialize our socket + self.socket = [[GCDAsyncSocket alloc] initWithDelegate:self delegateQueue:dq]; + } + } + + return self; +} + +- (BOOL)connectToHost:(NSString*)host onPort:(uint16_t)port error:(NSError **)errPtr { + return [socket connectToHost:host onPort:port error:errPtr]; +} + +- (BOOL)isDisconnected { + return [socket isDisconnected]; +} + +- (void)writeData:(NSData *)data withTimeout:(NSTimeInterval)timeout tag:(long)tag { + [socket writeData:data withTimeout:timeout tag:tag]; +} + +- (void)readDataToData:(NSData *)data withTimeout:(NSTimeInterval)timeout tag:(long)tag { + [socket readDataToData:data withTimeout:timeout tag:tag]; + +} + +- (void)disconnectAfterReadingAndWriting { + [socket disconnectAfterReadingAndWriting]; +} + +#pragma mark - +#pragma mark GCDAsyncSocketDelegate + +- (void)socket:(GCDAsyncSocket *)sock didReadData:(NSData *)data withTag:(long)tag { + if (self.delegate != nil) { + [delegate socket:(SKSocket*)self didReadData:data withTag:tag]; + } +} + +- (void)socket:(GCDAsyncSocket *)sock didReadPartialDataOfLength:(NSUInteger)partialLength tag:(long)tag { + if (self.delegate != nil) { + [delegate socket:(SKSocket*)self didReadPartialDataOfLength:partialLength tag:tag]; + } +} + +- (void)socket:(GCDAsyncSocket *)sock didConnectToHost:(NSString *)host port:(uint16_t)port { + if (self.delegate != nil) { + [delegate socket:(SKSocket*)self didConnectToHost:host port:port]; + } +} + +- (void)socketDidDisconnect:(GCDAsyncSocket *)sock withError:(NSError *)err { + if (self.delegate != nil) { + [delegate socketDidDisconnect:(SKSocket*)self withError:err]; + } +} + +@end diff --git a/StompKit/SKSocket/SKSocket.h b/StompKit/SKSocket/SKSocket.h new file mode 100644 index 0000000..688c130 --- /dev/null +++ b/StompKit/SKSocket/SKSocket.h @@ -0,0 +1,34 @@ +// +// SKSocket.h +// StompKit +// +// Created by Travis Bowers on 4/2/15. +// Copyright (c) 2015 Jeff Mesnil. All rights reserved. +// + +#ifndef StompKit_SKSocket_h +#define StompKit_SKSocket_h + +// forward declare +@class SKSocket; + +@protocol SKSocketDelegate +@optional +- (void)socket:(SKSocket *)sock didReadData:(NSData *)data withTag:(long)tag; +- (void)socket:(SKSocket *)sock didReadPartialDataOfLength:(NSUInteger)partialLength tag:(long)tag; +- (void)socket:(SKSocket *)sock didConnectToHost:(NSString *)host port:(uint16_t)port; +- (void)socketDidDisconnect:(SKSocket *)sock withError:(NSError *)err; +@end + + +@protocol SKSocket +- (id)initWithDelegate:(id)aDelegate delegateQueue:(dispatch_queue_t)dq; +- (BOOL)connectToHost:(NSString*)host onPort:(uint16_t)port error:(NSError **)errPtr; +- (BOOL)isDisconnected; +- (void)writeData:(NSData *)data withTimeout:(NSTimeInterval)timeout tag:(long)tag; +- (void)readDataToData:(NSData *)data withTimeout:(NSTimeInterval)timeout tag:(long)tag; +- (void)disconnectAfterReadingAndWriting; + +@end + +#endif diff --git a/StompKit/StompKit.m b/StompKit/StompKit.m index 5655298..837e2be 100644 --- a/StompKit/StompKit.m +++ b/StompKit/StompKit.m @@ -8,6 +8,7 @@ #import "StompKit.h" #import "GCDAsyncSocket.h" +#import "SKSocket.h" #define kDefaultTimeout 5 #define kVersion1_2 @"1.2" From d87ba72fb81dab171b5323bab4f35aa770dd29b0 Mon Sep 17 00:00:00 2001 From: Travis Bowers Date: Thu, 2 Apr 2015 10:49:37 -0500 Subject: [PATCH 03/14] Formatting change --- StompKit/SKSocket/SKRawSocket.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/StompKit/SKSocket/SKRawSocket.m b/StompKit/SKSocket/SKRawSocket.m index 83178e4..4265959 100644 --- a/StompKit/SKSocket/SKRawSocket.m +++ b/StompKit/SKSocket/SKRawSocket.m @@ -48,7 +48,7 @@ - (void)writeData:(NSData *)data withTimeout:(NSTimeInterval)timeout tag:(long)t - (void)readDataToData:(NSData *)data withTimeout:(NSTimeInterval)timeout tag:(long)tag { [socket readDataToData:data withTimeout:timeout tag:tag]; - + } - (void)disconnectAfterReadingAndWriting { From d31792e1bbbee9aa1ae7eede7f5687c1e54a4eb8 Mon Sep 17 00:00:00 2001 From: Travis Bowers Date: Thu, 2 Apr 2015 11:33:22 -0500 Subject: [PATCH 04/14] Migrated to using SKSocket protocol --- StompKit.xcodeproj/project.pbxproj | 8 ++++++++ StompKit/SKSocket/SKSocket.h | 5 +++++ StompKit/SKSocket/SKSocketUtility.h | 14 ++++++++++++++ StompKit/SKSocket/SKSocketUtility.m | 21 +++++++++++++++++++++ StompKit/StompKit.m | 27 ++++++++++++--------------- 5 files changed, 60 insertions(+), 15 deletions(-) create mode 100644 StompKit/SKSocket/SKSocketUtility.h create mode 100644 StompKit/SKSocket/SKSocketUtility.m diff --git a/StompKit.xcodeproj/project.pbxproj b/StompKit.xcodeproj/project.pbxproj index e73a678..dbb7788 100644 --- a/StompKit.xcodeproj/project.pbxproj +++ b/StompKit.xcodeproj/project.pbxproj @@ -9,6 +9,8 @@ /* Begin PBXBuildFile section */ 1F5B42B21ACD8AF100FABE04 /* SKRawSocket.m in Sources */ = {isa = PBXBuildFile; fileRef = 1F5B42B01ACD8AF100FABE04 /* SKRawSocket.m */; }; 1F5B42B31ACD8AF100FABE04 /* SKRawSocket.m in Sources */ = {isa = PBXBuildFile; fileRef = 1F5B42B01ACD8AF100FABE04 /* SKRawSocket.m */; }; + 1F5B42B61ACDA59500FABE04 /* SKSocketUtility.m in Sources */ = {isa = PBXBuildFile; fileRef = 1F5B42B51ACDA59500FABE04 /* SKSocketUtility.m */; }; + 1F5B42B71ACDA59500FABE04 /* SKSocketUtility.m in Sources */ = {isa = PBXBuildFile; fileRef = 1F5B42B51ACDA59500FABE04 /* SKSocketUtility.m */; }; 6C24B5EB8E0343E483E53CA2 /* libPods.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 37A4F2569A574CA6A0704DA6 /* libPods.a */; }; 932BA57C18056C4B00A03257 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 932BA57B18056C4B00A03257 /* Foundation.framework */; }; 932BA58118056C4B00A03257 /* StompKit.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 932BA58018056C4B00A03257 /* StompKit.h */; }; @@ -49,6 +51,8 @@ 1F5B42AF1ACD8AF100FABE04 /* SKRawSocket.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SKRawSocket.h; sourceTree = ""; }; 1F5B42B01ACD8AF100FABE04 /* SKRawSocket.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SKRawSocket.m; sourceTree = ""; }; 1F5B42B11ACD8AF100FABE04 /* SKSocket.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SKSocket.h; sourceTree = ""; }; + 1F5B42B41ACDA59500FABE04 /* SKSocketUtility.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SKSocketUtility.h; sourceTree = ""; }; + 1F5B42B51ACDA59500FABE04 /* SKSocketUtility.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SKSocketUtility.m; sourceTree = ""; }; 37A4F2569A574CA6A0704DA6 /* libPods.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libPods.a; sourceTree = BUILT_PRODUCTS_DIR; }; 4C55F3E01D49876D5B53EC05 /* Pods.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.debug.xcconfig; path = "Pods/Target Support Files/Pods/Pods.debug.xcconfig"; sourceTree = ""; }; 591868DBFE214F55AB478DA7 /* libPods-StompKitTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-StompKitTests.a"; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -114,6 +118,8 @@ 1F5B42AF1ACD8AF100FABE04 /* SKRawSocket.h */, 1F5B42B01ACD8AF100FABE04 /* SKRawSocket.m */, 1F5B42B11ACD8AF100FABE04 /* SKSocket.h */, + 1F5B42B41ACDA59500FABE04 /* SKSocketUtility.h */, + 1F5B42B51ACDA59500FABE04 /* SKSocketUtility.m */, ); path = SKSocket; sourceTree = ""; @@ -332,6 +338,7 @@ buildActionMask = 2147483647; files = ( 932BA58318056C4B00A03257 /* StompKit.m in Sources */, + 1F5B42B61ACDA59500FABE04 /* SKSocketUtility.m in Sources */, 1F5B42B21ACD8AF100FABE04 /* SKRawSocket.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -341,6 +348,7 @@ buildActionMask = 2147483647; files = ( 932BA59818056C4C00A03257 /* StompKitTests.m in Sources */, + 1F5B42B71ACDA59500FABE04 /* SKSocketUtility.m in Sources */, 1F5B42B31ACD8AF100FABE04 /* SKRawSocket.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/StompKit/SKSocket/SKSocket.h b/StompKit/SKSocket/SKSocket.h index 688c130..dffd535 100644 --- a/StompKit/SKSocket/SKSocket.h +++ b/StompKit/SKSocket/SKSocket.h @@ -9,9 +9,12 @@ #ifndef StompKit_SKSocket_h #define StompKit_SKSocket_h +#import "SKSocketUtility.h" + // forward declare @class SKSocket; +// SKSocket delegate interface @protocol SKSocketDelegate @optional - (void)socket:(SKSocket *)sock didReadData:(NSData *)data withTag:(long)tag; @@ -21,6 +24,8 @@ @end + +// SKSocket abstract interface @protocol SKSocket - (id)initWithDelegate:(id)aDelegate delegateQueue:(dispatch_queue_t)dq; - (BOOL)connectToHost:(NSString*)host onPort:(uint16_t)port error:(NSError **)errPtr; diff --git a/StompKit/SKSocket/SKSocketUtility.h b/StompKit/SKSocket/SKSocketUtility.h new file mode 100644 index 0000000..3215c3a --- /dev/null +++ b/StompKit/SKSocket/SKSocketUtility.h @@ -0,0 +1,14 @@ +// +// SKSocketUtility.h +// StompKit +// +// Created by Travis Bowers on 4/2/15. +// Copyright (c) 2015 Jeff Mesnil. All rights reserved. +// + +#import + +@interface SKSocketUtility : NSObject ++ (NSData*)zeroData; ++ (NSData*)lineFeedData; +@end diff --git a/StompKit/SKSocket/SKSocketUtility.m b/StompKit/SKSocket/SKSocketUtility.m new file mode 100644 index 0000000..b5a721e --- /dev/null +++ b/StompKit/SKSocket/SKSocketUtility.m @@ -0,0 +1,21 @@ +// +// SKSocketUtility.m +// StompKit +// +// Created by Travis Bowers on 4/2/15. +// Copyright (c) 2015 Jeff Mesnil. All rights reserved. +// + +#import "SKSocketUtility.h" + +@implementation SKSocketUtility + ++ (NSData*)zeroData { + return [NSData dataWithBytes:"" length:1]; +} + ++ (NSData*)lineFeedData { + return [NSData dataWithBytes:"\x0A" length:1]; +} + +@end diff --git a/StompKit/StompKit.m b/StompKit/StompKit.m index 837e2be..f40c023 100644 --- a/StompKit/StompKit.m +++ b/StompKit/StompKit.m @@ -7,8 +7,8 @@ // #import "StompKit.h" -#import "GCDAsyncSocket.h" -#import "SKSocket.h" +#import "SKSocket/SKSocket.h" +#import "SKSocket/SKRawSocket.h" #define kDefaultTimeout 5 #define kVersion1_2 @"1.2" @@ -54,7 +54,7 @@ @interface STOMPClient() -@property (nonatomic, retain) GCDAsyncSocket *socket; +@property (nonatomic, retain) id socket; @property (nonatomic, copy) NSString *host; @property (nonatomic) NSUInteger port; @property (nonatomic) NSString *clientHeartBeat; @@ -313,8 +313,7 @@ @implementation STOMPClient - (id)initWithHost:(NSString *)aHost port:(NSUInteger)aPort { if(self = [super init]) { - self.socket = [[GCDAsyncSocket alloc] initWithDelegate:self - delegateQueue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)]; + self.socket = [[SKRawSocket alloc] initWithDelegate:self delegateQueue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)]; self.host = aHost; self.port = aPort; idGenerator = 0; @@ -450,7 +449,8 @@ - (void)sendPing:(NSTimer *)timer { if ([self.socket isDisconnected]) { return; } - [self.socket writeData:[GCDAsyncSocket LFData] withTimeout:kDefaultTimeout tag:123]; + + [self.socket writeData:[SKSocketUtility lineFeedData] withTimeout:kDefaultTimeout tag:123]; LogDebug(@">>> PING"); } @@ -550,32 +550,29 @@ - (void)receivedFrame:(STOMPFrame *)frame { } - (void)readFrame { - [[self socket] readDataToData:[GCDAsyncSocket ZeroData] withTimeout:-1 tag:0]; + [[self socket] readDataToData:[SKSocketUtility zeroData] withTimeout:-1 tag:0]; } #pragma mark - -#pragma mark GCDAsyncSocketDelegate +#pragma mark SKSocketDelegate -- (void)socket:(GCDAsyncSocket *)sock - didReadData:(NSData *)data - withTag:(long)tag { +- (void)socket:(SKSocket *)sock didReadData:(NSData *)data withTag:(long)tag { serverActivity = CFAbsoluteTimeGetCurrent(); STOMPFrame *frame = [STOMPFrame STOMPFrameFromData:data]; [self receivedFrame:frame]; [self readFrame]; } -- (void)socket:(GCDAsyncSocket *)sock didReadPartialDataOfLength:(NSUInteger)partialLength tag:(long)tag { +- (void)socket:(SKSocket *)sock didReadPartialDataOfLength:(NSUInteger)partialLength tag:(long)tag { LogDebug(@"<<< PONG"); serverActivity = CFAbsoluteTimeGetCurrent(); } -- (void)socket:(GCDAsyncSocket *)sock didConnectToHost:(NSString *)host port:(uint16_t)port { +- (void)socket:(SKSocket *)sock didConnectToHost:(NSString *)host port:(uint16_t)port { [self readFrame]; } -- (void)socketDidDisconnect:(GCDAsyncSocket *)sock - withError:(NSError *)err { +- (void)socketDidDisconnect:(SKSocket *)sock withError:(NSError *)err { LogDebug(@"socket did disconnect"); if (!self.connected && self.connectionCompletionHandler) { self.connectionCompletionHandler(nil, err); From 87c2cd5054b388dc6eddbdf7c0cfe951e850c39b Mon Sep 17 00:00:00 2001 From: Travis Bowers Date: Thu, 2 Apr 2015 12:19:16 -0500 Subject: [PATCH 05/14] First pass integration of RocketSocket WebSocket strategy --- StompKit.xcodeproj/project.pbxproj | 8 +++ StompKit/SKSocket/SKRawSocket.h | 3 +- StompKit/SKSocket/SKRawSocket.m | 2 +- StompKit/SKSocket/SKWebSocket.h | 16 +++++ StompKit/SKSocket/SKWebSocket.m | 94 ++++++++++++++++++++++++++++++ 5 files changed, 120 insertions(+), 3 deletions(-) create mode 100644 StompKit/SKSocket/SKWebSocket.h create mode 100644 StompKit/SKSocket/SKWebSocket.m diff --git a/StompKit.xcodeproj/project.pbxproj b/StompKit.xcodeproj/project.pbxproj index dbb7788..9e65371 100644 --- a/StompKit.xcodeproj/project.pbxproj +++ b/StompKit.xcodeproj/project.pbxproj @@ -7,6 +7,8 @@ objects = { /* Begin PBXBuildFile section */ + 1F1632441ACDA8460047AE0C /* SKWebSocket.m in Sources */ = {isa = PBXBuildFile; fileRef = 1F1632431ACDA8460047AE0C /* SKWebSocket.m */; }; + 1F1632451ACDA8460047AE0C /* SKWebSocket.m in Sources */ = {isa = PBXBuildFile; fileRef = 1F1632431ACDA8460047AE0C /* SKWebSocket.m */; }; 1F5B42B21ACD8AF100FABE04 /* SKRawSocket.m in Sources */ = {isa = PBXBuildFile; fileRef = 1F5B42B01ACD8AF100FABE04 /* SKRawSocket.m */; }; 1F5B42B31ACD8AF100FABE04 /* SKRawSocket.m in Sources */ = {isa = PBXBuildFile; fileRef = 1F5B42B01ACD8AF100FABE04 /* SKRawSocket.m */; }; 1F5B42B61ACDA59500FABE04 /* SKSocketUtility.m in Sources */ = {isa = PBXBuildFile; fileRef = 1F5B42B51ACDA59500FABE04 /* SKSocketUtility.m */; }; @@ -48,6 +50,8 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ + 1F1632421ACDA8460047AE0C /* SKWebSocket.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SKWebSocket.h; sourceTree = ""; }; + 1F1632431ACDA8460047AE0C /* SKWebSocket.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SKWebSocket.m; sourceTree = ""; }; 1F5B42AF1ACD8AF100FABE04 /* SKRawSocket.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SKRawSocket.h; sourceTree = ""; }; 1F5B42B01ACD8AF100FABE04 /* SKRawSocket.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SKRawSocket.m; sourceTree = ""; }; 1F5B42B11ACD8AF100FABE04 /* SKSocket.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SKSocket.h; sourceTree = ""; }; @@ -120,6 +124,8 @@ 1F5B42B11ACD8AF100FABE04 /* SKSocket.h */, 1F5B42B41ACDA59500FABE04 /* SKSocketUtility.h */, 1F5B42B51ACDA59500FABE04 /* SKSocketUtility.m */, + 1F1632421ACDA8460047AE0C /* SKWebSocket.h */, + 1F1632431ACDA8460047AE0C /* SKWebSocket.m */, ); path = SKSocket; sourceTree = ""; @@ -338,6 +344,7 @@ buildActionMask = 2147483647; files = ( 932BA58318056C4B00A03257 /* StompKit.m in Sources */, + 1F1632441ACDA8460047AE0C /* SKWebSocket.m in Sources */, 1F5B42B61ACDA59500FABE04 /* SKSocketUtility.m in Sources */, 1F5B42B21ACD8AF100FABE04 /* SKRawSocket.m in Sources */, ); @@ -348,6 +355,7 @@ buildActionMask = 2147483647; files = ( 932BA59818056C4C00A03257 /* StompKitTests.m in Sources */, + 1F1632451ACDA8460047AE0C /* SKWebSocket.m in Sources */, 1F5B42B71ACDA59500FABE04 /* SKSocketUtility.m in Sources */, 1F5B42B31ACD8AF100FABE04 /* SKRawSocket.m in Sources */, ); diff --git a/StompKit/SKSocket/SKRawSocket.h b/StompKit/SKSocket/SKRawSocket.h index bccf496..cc38418 100644 --- a/StompKit/SKSocket/SKRawSocket.h +++ b/StompKit/SKSocket/SKRawSocket.h @@ -11,8 +11,7 @@ #import "SKSocket.h" -@interface SKRawSocket : NSObject -{ +@interface SKRawSocket : NSObject { } @end diff --git a/StompKit/SKSocket/SKRawSocket.m b/StompKit/SKSocket/SKRawSocket.m index 4265959..4414471 100644 --- a/StompKit/SKSocket/SKRawSocket.m +++ b/StompKit/SKSocket/SKRawSocket.m @@ -10,7 +10,7 @@ #import "SKRawSocket.h" #import "GCDAsyncSocket.h" -@interface SKRawSocket() +@interface SKRawSocket() @property (nonatomic, weak) id delegate; @property (nonatomic, retain) GCDAsyncSocket *socket; @end diff --git a/StompKit/SKSocket/SKWebSocket.h b/StompKit/SKSocket/SKWebSocket.h new file mode 100644 index 0000000..23250aa --- /dev/null +++ b/StompKit/SKSocket/SKWebSocket.h @@ -0,0 +1,16 @@ +// +// SKWebSocket.h +// StompKit +// +// Created by Travis Bowers on 4/2/15. +// Copyright (c) 2015 Jeff Mesnil. All rights reserved. +// + +#import +#import "SKSocket.h" + +extern NSString *const SKWebSocketErrorDomain; + +@interface SKWebSocket : NSObject { +} +@end diff --git a/StompKit/SKSocket/SKWebSocket.m b/StompKit/SKSocket/SKWebSocket.m new file mode 100644 index 0000000..f875b53 --- /dev/null +++ b/StompKit/SKSocket/SKWebSocket.m @@ -0,0 +1,94 @@ +// +// SKWebSocket.m +// StompKit +// +// Created by Travis Bowers on 4/2/15. +// Copyright (c) 2015 Jeff Mesnil. All rights reserved. +// + +#import "SKWebSocket.h" +#import "GCDAsyncSocket.h" +#import "SRWebSocket.h" + +NSString *const SKWebSocketErrorDomain = @"SKWebSocketErrorDomain"; + +@interface SKWebSocket() +@property (nonatomic, weak) id delegate; +@property (nonatomic, retain) SRWebSocket *socket; +@property (nonatomic, assign) BOOL connected; +@end + +@implementation SKWebSocket + +// synthesize properties +@synthesize delegate; +@synthesize socket; + +- (id)initWithDelegate:(id)aDelegate delegateQueue:(dispatch_queue_t)dq { + if((self = [super init])) { + if (aDelegate != nil) { + self.delegate = aDelegate; + self.connected = NO; + } + } + + return self; +} + +- (BOOL)connectToHost:(NSString*)host onPort:(uint16_t)port error:(NSError **)errPtr { + self.socket = [[SRWebSocket alloc] initWithURL:[NSURL URLWithString:host]]; + self.socket.delegate = self; + [self.socket open]; + return YES; +} + +- (BOOL)isDisconnected { + return !self.connected; +} + +- (void)writeData:(NSData *)data withTimeout:(NSTimeInterval)timeout tag:(long)tag { + [socket send:data]; +} + +- (void)readDataToData:(NSData *)data withTimeout:(NSTimeInterval)timeout tag:(long)tag { + // not supported + //[socket readDataToData:data withTimeout:timeout tag:tag]; +} + +- (void)disconnectAfterReadingAndWriting { + // not supported + //[socket disconnectAfterReadingAndWriting]; +} + +#pragma mark - +#pragma mark SRWebSocketDelegate +- (void)webSocket:(SRWebSocket *)webSocket didReceiveMessage:(id)message { + [delegate socket:(SKSocket*)self didReadData:message withTag:123]; +} + +- (void)webSocketDidOpen:(SRWebSocket *)webSocket { + self.connected = YES; + [delegate socket:(SKSocket*)self didConnectToHost:self.socket.url.absoluteString port:80]; +} + +- (void)webSocket:(SRWebSocket *)webSocket didFailWithError:(NSError *)error { + self.connected = NO; + [delegate socketDidDisconnect:(SKSocket*)self withError:error]; +} + +- (void)webSocket:(SRWebSocket *)webSocket didCloseWithCode:(NSInteger)code reason:(NSString *)reason wasClean:(BOOL)wasClean { + self.connected = NO; + + NSError *error = nil; + + if (wasClean == NO) { + NSDictionary *userInfo = @{NSLocalizedDescriptionKey: @"Socket did close", + NSLocalizedFailureReasonErrorKey: reason + }; + error = [NSError errorWithDomain:SKWebSocketErrorDomain code:-57 userInfo:userInfo]; + } + + [delegate socketDidDisconnect:(SKSocket*)self withError:error]; +} + +@end From 0b8f3975f56a39512192115887dce1f52fde39a7 Mon Sep 17 00:00:00 2001 From: Travis Bowers Date: Thu, 2 Apr 2015 12:21:58 -0500 Subject: [PATCH 06/14] Deprecate unusged async socket tag --- StompKit/SKSocket/SKRawSocket.m | 12 ++++++------ StompKit/SKSocket/SKSocket.h | 8 ++++---- StompKit/SKSocket/SKWebSocket.m | 6 +++--- StompKit/StompKit.m | 10 +++++----- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/StompKit/SKSocket/SKRawSocket.m b/StompKit/SKSocket/SKRawSocket.m index 4414471..fa9d770 100644 --- a/StompKit/SKSocket/SKRawSocket.m +++ b/StompKit/SKSocket/SKRawSocket.m @@ -42,12 +42,12 @@ - (BOOL)isDisconnected { return [socket isDisconnected]; } -- (void)writeData:(NSData *)data withTimeout:(NSTimeInterval)timeout tag:(long)tag { - [socket writeData:data withTimeout:timeout tag:tag]; +- (void)writeData:(NSData *)data withTimeout:(NSTimeInterval)timeout { + [socket writeData:data withTimeout:timeout tag:123]; } -- (void)readDataToData:(NSData *)data withTimeout:(NSTimeInterval)timeout tag:(long)tag { - [socket readDataToData:data withTimeout:timeout tag:tag]; +- (void)readDataToData:(NSData *)data withTimeout:(NSTimeInterval)timeout { + [socket readDataToData:data withTimeout:timeout tag:123]; } @@ -60,13 +60,13 @@ - (void)disconnectAfterReadingAndWriting { - (void)socket:(GCDAsyncSocket *)sock didReadData:(NSData *)data withTag:(long)tag { if (self.delegate != nil) { - [delegate socket:(SKSocket*)self didReadData:data withTag:tag]; + [delegate socket:(SKSocket*)self didReadData:data]; } } - (void)socket:(GCDAsyncSocket *)sock didReadPartialDataOfLength:(NSUInteger)partialLength tag:(long)tag { if (self.delegate != nil) { - [delegate socket:(SKSocket*)self didReadPartialDataOfLength:partialLength tag:tag]; + [delegate socket:(SKSocket*)self didReadPartialDataOfLength:partialLength]; } } diff --git a/StompKit/SKSocket/SKSocket.h b/StompKit/SKSocket/SKSocket.h index dffd535..67aa00a 100644 --- a/StompKit/SKSocket/SKSocket.h +++ b/StompKit/SKSocket/SKSocket.h @@ -17,8 +17,8 @@ // SKSocket delegate interface @protocol SKSocketDelegate @optional -- (void)socket:(SKSocket *)sock didReadData:(NSData *)data withTag:(long)tag; -- (void)socket:(SKSocket *)sock didReadPartialDataOfLength:(NSUInteger)partialLength tag:(long)tag; +- (void)socket:(SKSocket *)sock didReadData:(NSData *)data; +- (void)socket:(SKSocket *)sock didReadPartialDataOfLength:(NSUInteger)partialLength; - (void)socket:(SKSocket *)sock didConnectToHost:(NSString *)host port:(uint16_t)port; - (void)socketDidDisconnect:(SKSocket *)sock withError:(NSError *)err; @end @@ -30,8 +30,8 @@ - (id)initWithDelegate:(id)aDelegate delegateQueue:(dispatch_queue_t)dq; - (BOOL)connectToHost:(NSString*)host onPort:(uint16_t)port error:(NSError **)errPtr; - (BOOL)isDisconnected; -- (void)writeData:(NSData *)data withTimeout:(NSTimeInterval)timeout tag:(long)tag; -- (void)readDataToData:(NSData *)data withTimeout:(NSTimeInterval)timeout tag:(long)tag; +- (void)writeData:(NSData *)data withTimeout:(NSTimeInterval)timeout; +- (void)readDataToData:(NSData *)data withTimeout:(NSTimeInterval)timeout; - (void)disconnectAfterReadingAndWriting; @end diff --git a/StompKit/SKSocket/SKWebSocket.m b/StompKit/SKSocket/SKWebSocket.m index f875b53..301e85b 100644 --- a/StompKit/SKSocket/SKWebSocket.m +++ b/StompKit/SKSocket/SKWebSocket.m @@ -46,11 +46,11 @@ - (BOOL)isDisconnected { return !self.connected; } -- (void)writeData:(NSData *)data withTimeout:(NSTimeInterval)timeout tag:(long)tag { +- (void)writeData:(NSData *)data withTimeout:(NSTimeInterval)timeout { [socket send:data]; } -- (void)readDataToData:(NSData *)data withTimeout:(NSTimeInterval)timeout tag:(long)tag { +- (void)readDataToData:(NSData *)data withTimeout:(NSTimeInterval)timeout { // not supported //[socket readDataToData:data withTimeout:timeout tag:tag]; } @@ -63,7 +63,7 @@ - (void)disconnectAfterReadingAndWriting { #pragma mark - #pragma mark SRWebSocketDelegate - (void)webSocket:(SRWebSocket *)webSocket didReceiveMessage:(id)message { - [delegate socket:(SKSocket*)self didReadData:message withTag:123]; + [delegate socket:(SKSocket*)self didReadData:message]; } - (void)webSocketDidOpen:(SRWebSocket *)webSocket { diff --git a/StompKit/StompKit.m b/StompKit/StompKit.m index f40c023..21a51b5 100644 --- a/StompKit/StompKit.m +++ b/StompKit/StompKit.m @@ -442,7 +442,7 @@ - (void)sendFrameWithCommand:(NSString *)command STOMPFrame *frame = [[STOMPFrame alloc] initWithCommand:command headers:headers body:body]; LogDebug(@">>> %@", frame); NSData *data = [frame toData]; - [self.socket writeData:data withTimeout:kDefaultTimeout tag:123]; + [self.socket writeData:data withTimeout:kDefaultTimeout]; } - (void)sendPing:(NSTimer *)timer { @@ -450,7 +450,7 @@ - (void)sendPing:(NSTimer *)timer { return; } - [self.socket writeData:[SKSocketUtility lineFeedData] withTimeout:kDefaultTimeout tag:123]; + [self.socket writeData:[SKSocketUtility lineFeedData] withTimeout:kDefaultTimeout]; LogDebug(@">>> PING"); } @@ -550,20 +550,20 @@ - (void)receivedFrame:(STOMPFrame *)frame { } - (void)readFrame { - [[self socket] readDataToData:[SKSocketUtility zeroData] withTimeout:-1 tag:0]; + [[self socket] readDataToData:[SKSocketUtility zeroData] withTimeout:-1]; } #pragma mark - #pragma mark SKSocketDelegate -- (void)socket:(SKSocket *)sock didReadData:(NSData *)data withTag:(long)tag { +- (void)socket:(SKSocket *)sock didReadData:(NSData *)data { serverActivity = CFAbsoluteTimeGetCurrent(); STOMPFrame *frame = [STOMPFrame STOMPFrameFromData:data]; [self receivedFrame:frame]; [self readFrame]; } -- (void)socket:(SKSocket *)sock didReadPartialDataOfLength:(NSUInteger)partialLength tag:(long)tag { +- (void)socket:(SKSocket *)sock didReadPartialDataOfLength:(NSUInteger)partialLength { LogDebug(@"<<< PONG"); serverActivity = CFAbsoluteTimeGetCurrent(); } From 3a7b51e0691bde1a14b9f5a6b82031e21624639f Mon Sep 17 00:00:00 2001 From: Travis Bowers Date: Thu, 2 Apr 2015 14:02:27 -0500 Subject: [PATCH 07/14] Start of Stomp Test iOS app --- StompKit.xcodeproj/project.pbxproj | 182 ++++++++++++++++++ StompKitSandbox/AppDelegate.h | 17 ++ StompKitSandbox/AppDelegate.m | 45 +++++ StompKitSandbox/Base.lproj/LaunchScreen.xib | 41 ++++ StompKitSandbox/Base.lproj/Main.storyboard | 36 ++++ .../AppIcon.appiconset/Contents.json | 68 +++++++ StompKitSandbox/Info.plist | 47 +++++ StompKitSandbox/ViewController.h | 15 ++ StompKitSandbox/ViewController.m | 48 +++++ StompKitSandbox/main.m | 16 ++ 10 files changed, 515 insertions(+) create mode 100644 StompKitSandbox/AppDelegate.h create mode 100644 StompKitSandbox/AppDelegate.m create mode 100644 StompKitSandbox/Base.lproj/LaunchScreen.xib create mode 100644 StompKitSandbox/Base.lproj/Main.storyboard create mode 100644 StompKitSandbox/Images.xcassets/AppIcon.appiconset/Contents.json create mode 100644 StompKitSandbox/Info.plist create mode 100644 StompKitSandbox/ViewController.h create mode 100644 StompKitSandbox/ViewController.m create mode 100644 StompKitSandbox/main.m diff --git a/StompKit.xcodeproj/project.pbxproj b/StompKit.xcodeproj/project.pbxproj index 9e65371..00475c3 100644 --- a/StompKit.xcodeproj/project.pbxproj +++ b/StompKit.xcodeproj/project.pbxproj @@ -13,6 +13,16 @@ 1F5B42B31ACD8AF100FABE04 /* SKRawSocket.m in Sources */ = {isa = PBXBuildFile; fileRef = 1F5B42B01ACD8AF100FABE04 /* SKRawSocket.m */; }; 1F5B42B61ACDA59500FABE04 /* SKSocketUtility.m in Sources */ = {isa = PBXBuildFile; fileRef = 1F5B42B51ACDA59500FABE04 /* SKSocketUtility.m */; }; 1F5B42B71ACDA59500FABE04 /* SKSocketUtility.m in Sources */ = {isa = PBXBuildFile; fileRef = 1F5B42B51ACDA59500FABE04 /* SKSocketUtility.m */; }; + 1F8326881ACDC8EE000D3A09 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 1F8326871ACDC8EE000D3A09 /* main.m */; }; + 1F83268B1ACDC8EE000D3A09 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 1F83268A1ACDC8EE000D3A09 /* AppDelegate.m */; }; + 1F83268E1ACDC8EE000D3A09 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 1F83268D1ACDC8EE000D3A09 /* ViewController.m */; }; + 1F8326911ACDC8EE000D3A09 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 1F83268F1ACDC8EE000D3A09 /* Main.storyboard */; }; + 1F8326931ACDC8EE000D3A09 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 1F8326921ACDC8EE000D3A09 /* Images.xcassets */; }; + 1F8326961ACDC8EE000D3A09 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 1F8326941ACDC8EE000D3A09 /* LaunchScreen.xib */; }; + 1F8326A91ACDC8FC000D3A09 /* libStompKit.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 932BA57818056C4B00A03257 /* libStompKit.a */; }; + 1F8326AD1ACDC98D000D3A09 /* libPods-CocoaAsyncSocket.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 1F8326AC1ACDC98D000D3A09 /* libPods-CocoaAsyncSocket.a */; }; + 1F8326AF1ACDC994000D3A09 /* libPods-SocketRocket.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 1F8326AE1ACDC994000D3A09 /* libPods-SocketRocket.a */; }; + 1F8326B11ACDC9AE000D3A09 /* libicucore.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 1F8326B01ACDC9AE000D3A09 /* libicucore.dylib */; }; 6C24B5EB8E0343E483E53CA2 /* libPods.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 37A4F2569A574CA6A0704DA6 /* libPods.a */; }; 932BA57C18056C4B00A03257 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 932BA57B18056C4B00A03257 /* Foundation.framework */; }; 932BA58118056C4B00A03257 /* StompKit.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 932BA58018056C4B00A03257 /* StompKit.h */; }; @@ -57,6 +67,20 @@ 1F5B42B11ACD8AF100FABE04 /* SKSocket.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SKSocket.h; sourceTree = ""; }; 1F5B42B41ACDA59500FABE04 /* SKSocketUtility.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SKSocketUtility.h; sourceTree = ""; }; 1F5B42B51ACDA59500FABE04 /* SKSocketUtility.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SKSocketUtility.m; sourceTree = ""; }; + 1F8326831ACDC8EE000D3A09 /* StompKitSandbox.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = StompKitSandbox.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 1F8326861ACDC8EE000D3A09 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 1F8326871ACDC8EE000D3A09 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; + 1F8326891ACDC8EE000D3A09 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; + 1F83268A1ACDC8EE000D3A09 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; + 1F83268C1ACDC8EE000D3A09 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; + 1F83268D1ACDC8EE000D3A09 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; + 1F8326901ACDC8EE000D3A09 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; + 1F8326921ACDC8EE000D3A09 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; + 1F8326951ACDC8EE000D3A09 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; + 1F8326AA1ACDC982000D3A09 /* libPods.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libPods.a; path = "Pods/../build/Debug-iphoneos/libPods.a"; sourceTree = ""; }; + 1F8326AC1ACDC98D000D3A09 /* libPods-CocoaAsyncSocket.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = "libPods-CocoaAsyncSocket.a"; path = "Pods/../build/Debug-iphoneos/libPods-CocoaAsyncSocket.a"; sourceTree = ""; }; + 1F8326AE1ACDC994000D3A09 /* libPods-SocketRocket.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = "libPods-SocketRocket.a"; path = "Pods/../build/Debug-iphoneos/libPods-SocketRocket.a"; sourceTree = ""; }; + 1F8326B01ACDC9AE000D3A09 /* libicucore.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libicucore.dylib; path = usr/lib/libicucore.dylib; sourceTree = SDKROOT; }; 37A4F2569A574CA6A0704DA6 /* libPods.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libPods.a; sourceTree = BUILT_PRODUCTS_DIR; }; 4C55F3E01D49876D5B53EC05 /* Pods.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.debug.xcconfig; path = "Pods/Target Support Files/Pods/Pods.debug.xcconfig"; sourceTree = ""; }; 591868DBFE214F55AB478DA7 /* libPods-StompKitTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-StompKitTests.a"; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -81,6 +105,17 @@ /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ + 1F8326801ACDC8EE000D3A09 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 1F8326B11ACDC9AE000D3A09 /* libicucore.dylib in Frameworks */, + 1F8326AF1ACDC994000D3A09 /* libPods-SocketRocket.a in Frameworks */, + 1F8326AD1ACDC98D000D3A09 /* libPods-CocoaAsyncSocket.a in Frameworks */, + 1F8326A91ACDC8FC000D3A09 /* libStompKit.a in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; 932BA57518056C4B00A03257 /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; @@ -130,6 +165,30 @@ path = SKSocket; sourceTree = ""; }; + 1F8326841ACDC8EE000D3A09 /* StompKitSandbox */ = { + isa = PBXGroup; + children = ( + 1F8326891ACDC8EE000D3A09 /* AppDelegate.h */, + 1F83268A1ACDC8EE000D3A09 /* AppDelegate.m */, + 1F83268C1ACDC8EE000D3A09 /* ViewController.h */, + 1F83268D1ACDC8EE000D3A09 /* ViewController.m */, + 1F83268F1ACDC8EE000D3A09 /* Main.storyboard */, + 1F8326921ACDC8EE000D3A09 /* Images.xcassets */, + 1F8326941ACDC8EE000D3A09 /* LaunchScreen.xib */, + 1F8326851ACDC8EE000D3A09 /* Supporting Files */, + ); + path = StompKitSandbox; + sourceTree = ""; + }; + 1F8326851ACDC8EE000D3A09 /* Supporting Files */ = { + isa = PBXGroup; + children = ( + 1F8326861ACDC8EE000D3A09 /* Info.plist */, + 1F8326871ACDC8EE000D3A09 /* main.m */, + ); + name = "Supporting Files"; + sourceTree = ""; + }; 932BA56F18056C4B00A03257 = { isa = PBXGroup; children = ( @@ -139,6 +198,7 @@ 938827EE18056CA2009A1164 /* README.md */, 932BA57D18056C4B00A03257 /* StompKit */, 932BA59118056C4C00A03257 /* StompKitTests */, + 1F8326841ACDC8EE000D3A09 /* StompKitSandbox */, 932BA57A18056C4B00A03257 /* Frameworks */, 932BA57918056C4B00A03257 /* Products */, 1C9C6CD9BF6E5DAF68ADBC0D /* Pods */, @@ -150,6 +210,7 @@ children = ( 932BA57818056C4B00A03257 /* libStompKit.a */, 932BA58818056C4C00A03257 /* StompKitTests.xctest */, + 1F8326831ACDC8EE000D3A09 /* StompKitSandbox.app */, ); name = Products; sourceTree = ""; @@ -157,6 +218,10 @@ 932BA57A18056C4B00A03257 /* Frameworks */ = { isa = PBXGroup; children = ( + 1F8326B01ACDC9AE000D3A09 /* libicucore.dylib */, + 1F8326AE1ACDC994000D3A09 /* libPods-SocketRocket.a */, + 1F8326AC1ACDC98D000D3A09 /* libPods-CocoaAsyncSocket.a */, + 1F8326AA1ACDC982000D3A09 /* libPods.a */, 932BA57B18056C4B00A03257 /* Foundation.framework */, 932BA58918056C4C00A03257 /* XCTest.framework */, 932BA58C18056C4C00A03257 /* UIKit.framework */, @@ -198,6 +263,23 @@ /* End PBXGroup section */ /* Begin PBXNativeTarget section */ + 1F8326821ACDC8EE000D3A09 /* StompKitSandbox */ = { + isa = PBXNativeTarget; + buildConfigurationList = 1F8326A71ACDC8EE000D3A09 /* Build configuration list for PBXNativeTarget "StompKitSandbox" */; + buildPhases = ( + 1F83267F1ACDC8EE000D3A09 /* Sources */, + 1F8326801ACDC8EE000D3A09 /* Frameworks */, + 1F8326811ACDC8EE000D3A09 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = StompKitSandbox; + productName = StompKitSandbox; + productReference = 1F8326831ACDC8EE000D3A09 /* StompKitSandbox.app */; + productType = "com.apple.product-type.application"; + }; 932BA57718056C4B00A03257 /* StompKit */ = { isa = PBXNativeTarget; buildConfigurationList = 932BA59B18056C4C00A03257 /* Build configuration list for PBXNativeTarget "StompKit" */; @@ -245,6 +327,11 @@ attributes = { LastUpgradeCheck = 0620; ORGANIZATIONNAME = "Jeff Mesnil"; + TargetAttributes = { + 1F8326821ACDC8EE000D3A09 = { + CreatedOnToolsVersion = 6.2; + }; + }; }; buildConfigurationList = 932BA57318056C4B00A03257 /* Build configuration list for PBXProject "StompKit" */; compatibilityVersion = "Xcode 3.2"; @@ -252,6 +339,7 @@ hasScannedForEncodings = 0; knownRegions = ( en, + Base, ); mainGroup = 932BA56F18056C4B00A03257; productRefGroup = 932BA57918056C4B00A03257 /* Products */; @@ -260,11 +348,22 @@ targets = ( 932BA57718056C4B00A03257 /* StompKit */, 932BA58718056C4C00A03257 /* StompKitTests */, + 1F8326821ACDC8EE000D3A09 /* StompKitSandbox */, ); }; /* End PBXProject section */ /* Begin PBXResourcesBuildPhase section */ + 1F8326811ACDC8EE000D3A09 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 1F8326911ACDC8EE000D3A09 /* Main.storyboard in Resources */, + 1F8326961ACDC8EE000D3A09 /* LaunchScreen.xib in Resources */, + 1F8326931ACDC8EE000D3A09 /* Images.xcassets in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; 932BA58618056C4C00A03257 /* Resources */ = { isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; @@ -339,6 +438,16 @@ /* End PBXShellScriptBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ + 1F83267F1ACDC8EE000D3A09 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 1F83268E1ACDC8EE000D3A09 /* ViewController.m in Sources */, + 1F83268B1ACDC8EE000D3A09 /* AppDelegate.m in Sources */, + 1F8326881ACDC8EE000D3A09 /* main.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; 932BA57418056C4B00A03257 /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; @@ -372,6 +481,22 @@ /* End PBXTargetDependency section */ /* Begin PBXVariantGroup section */ + 1F83268F1ACDC8EE000D3A09 /* Main.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 1F8326901ACDC8EE000D3A09 /* Base */, + ); + name = Main.storyboard; + sourceTree = ""; + }; + 1F8326941ACDC8EE000D3A09 /* LaunchScreen.xib */ = { + isa = PBXVariantGroup; + children = ( + 1F8326951ACDC8EE000D3A09 /* Base */, + ); + name = LaunchScreen.xib; + sourceTree = ""; + }; 932BA59418056C4C00A03257 /* InfoPlist.strings */ = { isa = PBXVariantGroup; children = ( @@ -383,6 +508,53 @@ /* End PBXVariantGroup section */ /* Begin XCBuildConfiguration section */ + 1F8326A31ACDC8EE000D3A09 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_WARN_UNREACHABLE_CODE = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + INFOPLIST_FILE = StompKitSandbox/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 8.2; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + LIBRARY_SEARCH_PATHS = ( + "$(inherited)", + "$(PROJECT_DIR)/build/Debug-iphoneos", + ); + MTL_ENABLE_DEBUG_INFO = YES; + PRODUCT_NAME = "$(TARGET_NAME)"; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + 1F8326A41ACDC8EE000D3A09 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_WARN_UNREACHABLE_CODE = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + INFOPLIST_FILE = StompKitSandbox/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 8.2; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + LIBRARY_SEARCH_PATHS = ( + "$(inherited)", + "$(PROJECT_DIR)/build/Debug-iphoneos", + ); + MTL_ENABLE_DEBUG_INFO = NO; + PRODUCT_NAME = "$(TARGET_NAME)"; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Release; + }; 932BA59918056C4C00A03257 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { @@ -416,6 +588,7 @@ GCC_WARN_UNUSED_VARIABLE = YES; IPHONEOS_DEPLOYMENT_TARGET = 5.0; ONLY_ACTIVE_ARCH = YES; + OTHER_LDFLAGS = "-all_load"; SDKROOT = iphoneos; }; name = Debug; @@ -446,6 +619,7 @@ GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; IPHONEOS_DEPLOYMENT_TARGET = 5.0; + OTHER_LDFLAGS = "-all_load"; SDKROOT = iphoneos; VALIDATE_PRODUCT = YES; }; @@ -510,6 +684,14 @@ /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ + 1F8326A71ACDC8EE000D3A09 /* Build configuration list for PBXNativeTarget "StompKitSandbox" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 1F8326A31ACDC8EE000D3A09 /* Debug */, + 1F8326A41ACDC8EE000D3A09 /* Release */, + ); + defaultConfigurationIsVisible = 0; + }; 932BA57318056C4B00A03257 /* Build configuration list for PBXProject "StompKit" */ = { isa = XCConfigurationList; buildConfigurations = ( diff --git a/StompKitSandbox/AppDelegate.h b/StompKitSandbox/AppDelegate.h new file mode 100644 index 0000000..2d6eeee --- /dev/null +++ b/StompKitSandbox/AppDelegate.h @@ -0,0 +1,17 @@ +// +// AppDelegate.h +// StompKitSandbox +// +// Created by Travis Bowers on 4/2/15. +// Copyright (c) 2015 Jeff Mesnil. All rights reserved. +// + +#import + +@interface AppDelegate : UIResponder + +@property (strong, nonatomic) UIWindow *window; + + +@end + diff --git a/StompKitSandbox/AppDelegate.m b/StompKitSandbox/AppDelegate.m new file mode 100644 index 0000000..434c4fe --- /dev/null +++ b/StompKitSandbox/AppDelegate.m @@ -0,0 +1,45 @@ +// +// AppDelegate.m +// StompKitSandbox +// +// Created by Travis Bowers on 4/2/15. +// Copyright (c) 2015 Jeff Mesnil. All rights reserved. +// + +#import "AppDelegate.h" + +@interface AppDelegate () + +@end + +@implementation AppDelegate + + +- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { + // Override point for customization after application launch. + return YES; +} + +- (void)applicationWillResignActive:(UIApplication *)application { + // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. + // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. +} + +- (void)applicationDidEnterBackground:(UIApplication *)application { + // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. + // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. +} + +- (void)applicationWillEnterForeground:(UIApplication *)application { + // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. +} + +- (void)applicationDidBecomeActive:(UIApplication *)application { + // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. +} + +- (void)applicationWillTerminate:(UIApplication *)application { + // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. +} + +@end diff --git a/StompKitSandbox/Base.lproj/LaunchScreen.xib b/StompKitSandbox/Base.lproj/LaunchScreen.xib new file mode 100644 index 0000000..c27d8db --- /dev/null +++ b/StompKitSandbox/Base.lproj/LaunchScreen.xib @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/StompKitSandbox/Base.lproj/Main.storyboard b/StompKitSandbox/Base.lproj/Main.storyboard new file mode 100644 index 0000000..39337f4 --- /dev/null +++ b/StompKitSandbox/Base.lproj/Main.storyboard @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/StompKitSandbox/Images.xcassets/AppIcon.appiconset/Contents.json b/StompKitSandbox/Images.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000..36d2c80 --- /dev/null +++ b/StompKitSandbox/Images.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,68 @@ +{ + "images" : [ + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "3x" + }, + { + "idiom" : "ipad", + "size" : "29x29", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "29x29", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "40x40", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "40x40", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "76x76", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "76x76", + "scale" : "2x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/StompKitSandbox/Info.plist b/StompKitSandbox/Info.plist new file mode 100644 index 0000000..c4b476a --- /dev/null +++ b/StompKitSandbox/Info.plist @@ -0,0 +1,47 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + com.tbowers.stompkit.$(PRODUCT_NAME:rfc1034identifier) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1 + LSRequiresIPhoneOS + + UILaunchStoryboardName + LaunchScreen + UIMainStoryboardFile + Main + UIRequiredDeviceCapabilities + + armv7 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + + diff --git a/StompKitSandbox/ViewController.h b/StompKitSandbox/ViewController.h new file mode 100644 index 0000000..9fd81bb --- /dev/null +++ b/StompKitSandbox/ViewController.h @@ -0,0 +1,15 @@ +// +// ViewController.h +// StompKitSandbox +// +// Created by Travis Bowers on 4/2/15. +// Copyright (c) 2015 Jeff Mesnil. All rights reserved. +// + +#import + +@interface ViewController : UIViewController + + +@end + diff --git a/StompKitSandbox/ViewController.m b/StompKitSandbox/ViewController.m new file mode 100644 index 0000000..1338618 --- /dev/null +++ b/StompKitSandbox/ViewController.m @@ -0,0 +1,48 @@ +// +// ViewController.m +// StompKitSandbox +// +// Created by Travis Bowers on 4/2/15. +// Copyright (c) 2015 Jeff Mesnil. All rights reserved. +// + +#import "ViewController.h" +#import "StompKit.h" + +@interface ViewController () + +@end + +@implementation ViewController + +- (void)viewDidLoad { + [super viewDidLoad]; + // Do any additional setup after loading the view, typically from a nib. +} + +- (void)didReceiveMemoryWarning { + [super didReceiveMemoryWarning]; + // Dispose of any resources that can be recreated. +} + +- (IBAction)connectButtonPressed:(id)sender { + // create the client + STOMPClient *client = [[STOMPClient alloc] initWithHost:@"localhost" + port:61613]; + // connect to the broker + [client connectWithLogin:@"mylogin" + passcode:@"mypassword" + completionHandler:^(STOMPFrame *_, NSError *error) { + if (error) { + NSLog(@"%@", error); + return; + } + + // send a message + [client sendTo:@"/queue/myqueue" body:@"Hello, iOS!"]; + // and disconnect + [client disconnect]; + }]; +} + +@end diff --git a/StompKitSandbox/main.m b/StompKitSandbox/main.m new file mode 100644 index 0000000..fc97f6d --- /dev/null +++ b/StompKitSandbox/main.m @@ -0,0 +1,16 @@ +// +// main.m +// StompKitSandbox +// +// Created by Travis Bowers on 4/2/15. +// Copyright (c) 2015 Jeff Mesnil. All rights reserved. +// + +#import +#import "AppDelegate.h" + +int main(int argc, char * argv[]) { + @autoreleasepool { + return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); + } +} From f019fa73964c27969f16c9b926fd4d4b07261ac1 Mon Sep 17 00:00:00 2001 From: Travis Bowers Date: Thu, 2 Apr 2015 14:39:03 -0500 Subject: [PATCH 08/14] Hooked in events for connect, disconnect, and sample send --- StompKit/SKSocket/SKWebSocket.m | 3 +- StompKit/StompKit.m | 40 +++++++++++++--------- StompKitSandbox/Base.lproj/Main.storyboard | 18 ++++++++++ StompKitSandbox/ViewController.m | 21 +++++++++--- 4 files changed, 58 insertions(+), 24 deletions(-) diff --git a/StompKit/SKSocket/SKWebSocket.m b/StompKit/SKSocket/SKWebSocket.m index 301e85b..3409d9f 100644 --- a/StompKit/SKSocket/SKWebSocket.m +++ b/StompKit/SKSocket/SKWebSocket.m @@ -56,8 +56,7 @@ - (void)readDataToData:(NSData *)data withTimeout:(NSTimeInterval)timeout { } - (void)disconnectAfterReadingAndWriting { - // not supported - //[socket disconnectAfterReadingAndWriting]; + [socket close]; } #pragma mark - diff --git a/StompKit/StompKit.m b/StompKit/StompKit.m index 21a51b5..729ad5f 100644 --- a/StompKit/StompKit.m +++ b/StompKit/StompKit.m @@ -9,6 +9,7 @@ #import "StompKit.h" #import "SKSocket/SKSocket.h" #import "SKSocket/SKRawSocket.h" +#import "SKSocket/SKWebSocket.h" #define kDefaultTimeout 5 #define kVersion1_2 @"1.2" @@ -64,6 +65,7 @@ @interface STOMPClient() @property (nonatomic, copy) void (^disconnectedHandler)(NSError *error); @property (nonatomic, copy) void (^connectionCompletionHandler)(STOMPFrame *connectedFrame, NSError *error); @property (nonatomic, retain) NSMutableDictionary *subscriptions; +@property (nonatomic, strong) NSMutableDictionary *connectHeaders; - (void) sendFrameWithCommand:(NSString *)command headers:(NSDictionary *)headers @@ -302,6 +304,7 @@ @implementation STOMPClient @synthesize socket, host, port; @synthesize connectionCompletionHandler, disconnectedHandler, receiptHandler, errorHandler; @synthesize subscriptions; +@synthesize connectHeaders; @synthesize pinger, ponger; int idGenerator; @@ -313,7 +316,9 @@ @implementation STOMPClient - (id)initWithHost:(NSString *)aHost port:(NSUInteger)aPort { if(self = [super init]) { - self.socket = [[SKRawSocket alloc] initWithDelegate:self delegateQueue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)]; + //self.socket = [[SKRawSocket alloc] initWithDelegate:self delegateQueue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)]; + self.socket = [[SKWebSocket alloc] initWithDelegate:self delegateQueue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)]; + self.host = aHost; self.port = aPort; idGenerator = 0; @@ -334,6 +339,9 @@ - (void)connectWithLogin:(NSString *)login - (void)connectWithHeaders:(NSDictionary *)headers completionHandler:(void (^)(STOMPFrame *connectedFrame, NSError *error))completionHandler { self.connectionCompletionHandler = completionHandler; + + // build connection headers + self.connectHeaders = [[NSMutableDictionary alloc] initWithDictionary:headers]; NSError *err; if(![self.socket connectToHost:host onPort:port error:&err]) { @@ -341,21 +349,6 @@ - (void)connectWithHeaders:(NSDictionary *)headers self.connectionCompletionHandler(nil, err); } } - - NSMutableDictionary *connectHeaders = [[NSMutableDictionary alloc] initWithDictionary:headers]; - connectHeaders[kHeaderAcceptVersion] = kVersion1_2; - if (!connectHeaders[kHeaderHost]) { - connectHeaders[kHeaderHost] = host; - } - if (!connectHeaders[kHeaderHeartBeat]) { - connectHeaders[kHeaderHeartBeat] = self.clientHeartBeat; - } else { - self.clientHeartBeat = connectHeaders[kHeaderHeartBeat]; - } - - [self sendFrameWithCommand:kCommandConnect - headers:connectHeaders - body: nil]; } - (void)sendTo:(NSString *)destination @@ -568,7 +561,20 @@ - (void)socket:(SKSocket *)sock didReadPartialDataOfLength:(NSUInteger)partialLe serverActivity = CFAbsoluteTimeGetCurrent(); } -- (void)socket:(SKSocket *)sock didConnectToHost:(NSString *)host port:(uint16_t)port { +- (void)socket:(SKSocket *)sock didConnectToHost:(NSString *)aHost port:(uint16_t)aPort { + self.connectHeaders[kHeaderAcceptVersion] = kVersion1_2; + if (!connectHeaders[kHeaderHost]) { + connectHeaders[kHeaderHost] = host; + } + if (!connectHeaders[kHeaderHeartBeat]) { + connectHeaders[kHeaderHeartBeat] = self.clientHeartBeat; + } else { + self.clientHeartBeat = connectHeaders[kHeaderHeartBeat]; + } + + [self sendFrameWithCommand:kCommandConnect + headers:connectHeaders + body: nil]; [self readFrame]; } diff --git a/StompKitSandbox/Base.lproj/Main.storyboard b/StompKitSandbox/Base.lproj/Main.storyboard index 39337f4..8ceb68f 100644 --- a/StompKitSandbox/Base.lproj/Main.storyboard +++ b/StompKitSandbox/Base.lproj/Main.storyboard @@ -25,6 +25,24 @@ + + diff --git a/StompKitSandbox/ViewController.m b/StompKitSandbox/ViewController.m index 1338618..33929cf 100644 --- a/StompKitSandbox/ViewController.m +++ b/StompKitSandbox/ViewController.m @@ -10,10 +10,11 @@ #import "StompKit.h" @interface ViewController () - +@property (nonatomic, strong) STOMPClient *client; @end @implementation ViewController +@synthesize client; - (void)viewDidLoad { [super viewDidLoad]; @@ -27,11 +28,10 @@ - (void)didReceiveMemoryWarning { - (IBAction)connectButtonPressed:(id)sender { // create the client - STOMPClient *client = [[STOMPClient alloc] initWithHost:@"localhost" - port:61613]; + client = [[STOMPClient alloc] initWithHost:@"ws://le3.liveexpertdev.net:61614/stomp" port:0]; // connect to the broker - [client connectWithLogin:@"mylogin" - passcode:@"mypassword" + [client connectWithLogin:@"admin" + passcode:@"admin" completionHandler:^(STOMPFrame *_, NSError *error) { if (error) { NSLog(@"%@", error); @@ -45,4 +45,15 @@ - (IBAction)connectButtonPressed:(id)sender { }]; } +- (IBAction)disconnectButtonPressed:(id)sender { + if (client != nil) { + [client disconnect]; + } +} + +- (IBAction)sendButtonPressed:(id)sender { + // send a message + [client sendTo:@"/queue/travis" body:@"Hello, iOS!"]; +} + @end From 3597560be4466419f2679ca022d42f9ba21352f3 Mon Sep 17 00:00:00 2001 From: Travis Bowers Date: Sat, 4 Apr 2015 10:21:05 -0400 Subject: [PATCH 09/14] Removed need for admin login from consuming app. Added test application (sending to queue working). Split out delegate to receive NSData (raw socket) or NSString (web socket --- StompKit/SKSocket/SKRawSocket.m | 2 +- StompKit/SKSocket/SKSocket.h | 3 +- StompKit/SKSocket/SKWebSocket.m | 5 ++- StompKit/StompKit.h | 1 + StompKit/StompKit.m | 63 +++++++++++++++++++++----------- StompKitSandbox/ViewController.m | 26 ++++++------- 6 files changed, 61 insertions(+), 39 deletions(-) diff --git a/StompKit/SKSocket/SKRawSocket.m b/StompKit/SKSocket/SKRawSocket.m index fa9d770..dbdfa15 100644 --- a/StompKit/SKSocket/SKRawSocket.m +++ b/StompKit/SKSocket/SKRawSocket.m @@ -60,7 +60,7 @@ - (void)disconnectAfterReadingAndWriting { - (void)socket:(GCDAsyncSocket *)sock didReadData:(NSData *)data withTag:(long)tag { if (self.delegate != nil) { - [delegate socket:(SKSocket*)self didReadData:data]; + [delegate socket:(SKSocket*)self didReadDataWithData:data]; } } diff --git a/StompKit/SKSocket/SKSocket.h b/StompKit/SKSocket/SKSocket.h index 67aa00a..73ca335 100644 --- a/StompKit/SKSocket/SKSocket.h +++ b/StompKit/SKSocket/SKSocket.h @@ -17,7 +17,8 @@ // SKSocket delegate interface @protocol SKSocketDelegate @optional -- (void)socket:(SKSocket *)sock didReadData:(NSData *)data; +- (void)socket:(SKSocket *)sock didReadDataWithData:(NSData *)data; +- (void)socket:(SKSocket *)sock didReadDataWithString:(NSString *)data; - (void)socket:(SKSocket *)sock didReadPartialDataOfLength:(NSUInteger)partialLength; - (void)socket:(SKSocket *)sock didConnectToHost:(NSString *)host port:(uint16_t)port; - (void)socketDidDisconnect:(SKSocket *)sock withError:(NSError *)err; diff --git a/StompKit/SKSocket/SKWebSocket.m b/StompKit/SKSocket/SKWebSocket.m index 3409d9f..8b34c9b 100644 --- a/StompKit/SKSocket/SKWebSocket.m +++ b/StompKit/SKSocket/SKWebSocket.m @@ -47,7 +47,8 @@ - (BOOL)isDisconnected { } - (void)writeData:(NSData *)data withTimeout:(NSTimeInterval)timeout { - [socket send:data]; + // convert data to string and send + [socket send:[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]]; } - (void)readDataToData:(NSData *)data withTimeout:(NSTimeInterval)timeout { @@ -62,7 +63,7 @@ - (void)disconnectAfterReadingAndWriting { #pragma mark - #pragma mark SRWebSocketDelegate - (void)webSocket:(SRWebSocket *)webSocket didReceiveMessage:(id)message { - [delegate socket:(SKSocket*)self didReadData:message]; + [delegate socket:(SKSocket*)self didReadDataWithString:message]; } - (void)webSocketDidOpen:(SRWebSocket *)webSocket { diff --git a/StompKit/StompKit.h b/StompKit/StompKit.h index 93a4e29..7a312de 100644 --- a/StompKit/StompKit.h +++ b/StompKit/StompKit.h @@ -91,6 +91,7 @@ typedef void (^STOMPMessageHandler)(STOMPMessage *message); - (id)initWithHost:(NSString *)theHost port:(NSUInteger)thePort; +- (void)connectWithCompletionHandler:(void (^)(STOMPFrame *connectedFrame, NSError *error))completionHandler; - (void)connectWithLogin:(NSString *)login passcode:(NSString *)passcode completionHandler:(void (^)(STOMPFrame *connectedFrame, NSError *error))completionHandler; diff --git a/StompKit/StompKit.m b/StompKit/StompKit.m index 729ad5f..25fc111 100644 --- a/StompKit/StompKit.m +++ b/StompKit/StompKit.m @@ -117,9 +117,7 @@ - (NSData *)toData { return [[self toString] dataUsingEncoding:NSUTF8StringEncoding]; } -+ (STOMPFrame *) STOMPFrameFromData:(NSData *)data { - NSData *strData = [data subdataWithRange:NSMakeRange(0, [data length])]; - NSString *msg = [[NSString alloc] initWithData:strData encoding:NSUTF8StringEncoding]; ++ (STOMPFrame *) STOMPFrameFromDataString:(NSString *)msg { LogDebug(@"<<< %@", msg); NSMutableArray *contents = (NSMutableArray *)[[msg componentsSeparatedByString:kLineFeed] mutableCopy]; while ([contents count] > 0 && [contents[0] isEqual:@""]) { @@ -329,6 +327,10 @@ - (id)initWithHost:(NSString *)aHost return self; } +- (void)connectWithCompletionHandler:(void (^)(STOMPFrame *connectedFrame, NSError *error))completionHandler { + [self connectWithHeaders:nil completionHandler:completionHandler]; +} + - (void)connectWithLogin:(NSString *)login passcode:(NSString *)passcode completionHandler:(void (^)(STOMPFrame *connectedFrame, NSError *error))completionHandler { @@ -341,8 +343,13 @@ - (void)connectWithHeaders:(NSDictionary *)headers self.connectionCompletionHandler = completionHandler; // build connection headers - self.connectHeaders = [[NSMutableDictionary alloc] initWithDictionary:headers]; - + if (headers != nil) { + self.connectHeaders = [[NSMutableDictionary alloc] initWithDictionary:headers]; + } + else { + self.connectHeaders = [[NSMutableDictionary alloc] init]; + } + NSError *err; if(![self.socket connectToHost:host onPort:port error:&err]) { if (self.connectionCompletionHandler) { @@ -546,12 +553,24 @@ - (void)readFrame { [[self socket] readDataToData:[SKSocketUtility zeroData] withTimeout:-1]; } ++ (NSString *)stringFromData:(NSData*)data { + return [[NSString alloc] initWithData:[data copy] encoding:NSUTF8StringEncoding]; + +} + #pragma mark - #pragma mark SKSocketDelegate -- (void)socket:(SKSocket *)sock didReadData:(NSData *)data { +- (void)socket:(SKSocket *)sock didReadDataWithData:(NSData *)data { serverActivity = CFAbsoluteTimeGetCurrent(); - STOMPFrame *frame = [STOMPFrame STOMPFrameFromData:data]; + STOMPFrame *frame = [STOMPFrame STOMPFrameFromDataString:[STOMPClient stringFromData:data]]; + [self receivedFrame:frame]; + [self readFrame]; +} + +- (void)socket:(SKSocket *)sock didReadDataWithString:(NSString *)data { + serverActivity = CFAbsoluteTimeGetCurrent(); + STOMPFrame *frame = [STOMPFrame STOMPFrameFromDataString:data]; [self receivedFrame:frame]; [self readFrame]; } @@ -562,20 +581,22 @@ - (void)socket:(SKSocket *)sock didReadPartialDataOfLength:(NSUInteger)partialLe } - (void)socket:(SKSocket *)sock didConnectToHost:(NSString *)aHost port:(uint16_t)aPort { - self.connectHeaders[kHeaderAcceptVersion] = kVersion1_2; - if (!connectHeaders[kHeaderHost]) { - connectHeaders[kHeaderHost] = host; - } - if (!connectHeaders[kHeaderHeartBeat]) { - connectHeaders[kHeaderHeartBeat] = self.clientHeartBeat; - } else { - self.clientHeartBeat = connectHeaders[kHeaderHeartBeat]; - } - - [self sendFrameWithCommand:kCommandConnect - headers:connectHeaders - body: nil]; - [self readFrame]; + dispatch_async(dispatch_get_main_queue(), ^{ + self.connectHeaders[kHeaderAcceptVersion] = kVersion1_2; + if (!connectHeaders[kHeaderHost]) { + connectHeaders[kHeaderHost] = host; + } + if (!connectHeaders[kHeaderHeartBeat]) { + connectHeaders[kHeaderHeartBeat] = self.clientHeartBeat; + } else { + self.clientHeartBeat = connectHeaders[kHeaderHeartBeat]; + } + + [self sendFrameWithCommand:kCommandConnect + headers:connectHeaders + body: nil]; + [self readFrame]; + }); } - (void)socketDidDisconnect:(SKSocket *)sock withError:(NSError *)err { diff --git a/StompKitSandbox/ViewController.m b/StompKitSandbox/ViewController.m index 33929cf..2b5e0c2 100644 --- a/StompKitSandbox/ViewController.m +++ b/StompKitSandbox/ViewController.m @@ -30,19 +30,17 @@ - (IBAction)connectButtonPressed:(id)sender { // create the client client = [[STOMPClient alloc] initWithHost:@"ws://le3.liveexpertdev.net:61614/stomp" port:0]; // connect to the broker - [client connectWithLogin:@"admin" - passcode:@"admin" - completionHandler:^(STOMPFrame *_, NSError *error) { - if (error) { - NSLog(@"%@", error); - return; - } - - // send a message - [client sendTo:@"/queue/myqueue" body:@"Hello, iOS!"]; - // and disconnect - [client disconnect]; - }]; + [client connectWithCompletionHandler:^(STOMPFrame *_, NSError *error) { + if (error) { + NSLog(@"%@", error); + return; + } + + // send a message + [client sendTo:@"/queue/myqueue" body:@"Hello, iOS!"]; + // and disconnect + [client disconnect]; + }]; } - (IBAction)disconnectButtonPressed:(id)sender { @@ -53,7 +51,7 @@ - (IBAction)disconnectButtonPressed:(id)sender { - (IBAction)sendButtonPressed:(id)sender { // send a message - [client sendTo:@"/queue/travis" body:@"Hello, iOS!"]; + [client sendTo:@"/queue/myqueue" body:@"Hello, iOS!"]; } @end From 832fef9456e0636f74b1f1fa317387c53a7611f1 Mon Sep 17 00:00:00 2001 From: Travis Bowers Date: Sat, 4 Apr 2015 10:26:38 -0400 Subject: [PATCH 10/14] Added initializer for just host w/o port --- StompKit/StompKit.h | 4 ++-- StompKit/StompKit.m | 7 +++++-- StompKitSandbox/ViewController.m | 4 ++-- StompKitTests/StompKitTests.m | 4 ++-- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/StompKit/StompKit.h b/StompKit/StompKit.h index 7a312de..906dcda 100644 --- a/StompKit/StompKit.h +++ b/StompKit/StompKit.h @@ -88,8 +88,8 @@ typedef void (^STOMPMessageHandler)(STOMPMessage *message); @property (nonatomic, copy) void (^errorHandler)(NSError *error); @property (nonatomic, assign) BOOL connected; -- (id)initWithHost:(NSString *)theHost - port:(NSUInteger)thePort; +- (id)initWithHost:(NSString *)theHost; +- (id)initWithHost:(NSString *)theHost andPort:(NSUInteger)thePort; - (void)connectWithCompletionHandler:(void (^)(STOMPFrame *connectedFrame, NSError *error))completionHandler; - (void)connectWithLogin:(NSString *)login diff --git a/StompKit/StompKit.m b/StompKit/StompKit.m index 25fc111..0c901bd 100644 --- a/StompKit/StompKit.m +++ b/StompKit/StompKit.m @@ -311,8 +311,11 @@ @implementation STOMPClient #pragma mark - #pragma mark Public API -- (id)initWithHost:(NSString *)aHost - port:(NSUInteger)aPort { +- (id)initWithHost:(NSString *)theHost { + return [self initWithHost:theHost andPort:0]; +} + +- (id)initWithHost:(NSString *)aHost andPort:(NSUInteger)aPort { if(self = [super init]) { //self.socket = [[SKRawSocket alloc] initWithDelegate:self delegateQueue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)]; self.socket = [[SKWebSocket alloc] initWithDelegate:self delegateQueue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)]; diff --git a/StompKitSandbox/ViewController.m b/StompKitSandbox/ViewController.m index 2b5e0c2..2034b51 100644 --- a/StompKitSandbox/ViewController.m +++ b/StompKitSandbox/ViewController.m @@ -28,7 +28,7 @@ - (void)didReceiveMemoryWarning { - (IBAction)connectButtonPressed:(id)sender { // create the client - client = [[STOMPClient alloc] initWithHost:@"ws://le3.liveexpertdev.net:61614/stomp" port:0]; + client = [[STOMPClient alloc] initWithHost:@"ws://localhost:61614/stomp"]; // connect to the broker [client connectWithCompletionHandler:^(STOMPFrame *_, NSError *error) { if (error) { @@ -37,7 +37,7 @@ - (IBAction)connectButtonPressed:(id)sender { } // send a message - [client sendTo:@"/queue/myqueue" body:@"Hello, iOS!"]; + [client sendTo:@"/queue/bowers" body:@"Hello, iOS!"]; // and disconnect [client disconnect]; }]; diff --git a/StompKitTests/StompKitTests.m b/StompKitTests/StompKitTests.m index 83ece70..98d14df 100644 --- a/StompKitTests/StompKitTests.m +++ b/StompKitTests/StompKitTests.m @@ -30,7 +30,7 @@ - (void)setUp [super setUp]; self.client = [[STOMPClient alloc] initWithHost:HOST - port:PORT]; + andPort:PORT]; } - (void)tearDown @@ -43,7 +43,7 @@ - (void)testInvalidServerInfo { dispatch_semaphore_t errorReceived = dispatch_semaphore_create(0); - STOMPClient *otherClient = [[STOMPClient alloc] initWithHost:@"invalid host" port:61613]; + STOMPClient *otherClient = [[STOMPClient alloc] initWithHost:@"invalid host" andPort:61613]; [otherClient connectWithLogin:LOGIN passcode:PASSCODE completionHandler:^(STOMPFrame *connectedFrame, NSError *error) { From c8d71a045f831560a0ef67f9635d0b11071d9b53 Mon Sep 17 00:00:00 2001 From: Travis Bowers Date: Sat, 4 Apr 2015 10:28:27 -0400 Subject: [PATCH 11/14] Determine strategy based on host prefix --- StompKit/StompKit.m | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/StompKit/StompKit.m b/StompKit/StompKit.m index 0c901bd..b4baf8e 100644 --- a/StompKit/StompKit.m +++ b/StompKit/StompKit.m @@ -317,9 +317,14 @@ - (id)initWithHost:(NSString *)theHost { - (id)initWithHost:(NSString *)aHost andPort:(NSUInteger)aPort { if(self = [super init]) { - //self.socket = [[SKRawSocket alloc] initWithDelegate:self delegateQueue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)]; - self.socket = [[SKWebSocket alloc] initWithDelegate:self delegateQueue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)]; - + // rough comparision now to determine whether or not use websocket + if ([aHost hasPrefix:@"ws://"]) { + self.socket = [[SKWebSocket alloc] initWithDelegate:self delegateQueue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)]; + } + else { + self.socket = [[SKRawSocket alloc] initWithDelegate:self delegateQueue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)]; + } + self.host = aHost; self.port = aPort; idGenerator = 0; From 9d0a6ff74d3af5e5650dc6c7ba8c5a0f7e69d202 Mon Sep 17 00:00:00 2001 From: Travis Bowers Date: Wed, 8 Apr 2015 09:20:11 -0500 Subject: [PATCH 12/14] Updated podspec to include socket rocket --- StompKit.podspec | 1 + 1 file changed, 1 insertion(+) diff --git a/StompKit.podspec b/StompKit.podspec index ecd302c..213b9f2 100644 --- a/StompKit.podspec +++ b/StompKit.podspec @@ -11,4 +11,5 @@ Pod::Spec.new do |s| s.public_header_files = 'StompKit/StompKit.h' s.requires_arc = true s.dependency 'CocoaAsyncSocket', '7.3.4' + s.dependency 'SocketRocket', '0.3.1-beta2' end From 5ba777299ef28af503e195a0bf4b9eeecd5a46b7 Mon Sep 17 00:00:00 2001 From: Travis Bowers Date: Tue, 9 Jun 2015 12:48:23 -0500 Subject: [PATCH 13/14] Updated podspec --- StompKit.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/StompKit.podspec b/StompKit.podspec index 213b9f2..8f5f818 100644 --- a/StompKit.podspec +++ b/StompKit.podspec @@ -8,7 +8,7 @@ Pod::Spec.new do |s| s.source = { :git => 'https://github.com/mobile-web-messaging/StompKit.git', :tag => "#{s.version}" } s.platform = :ios, 5.0 s.source_files = 'StompKit/*.{h,m}' - s.public_header_files = 'StompKit/StompKit.h' + s.public_header_files = 'StompKit/StompKit.h', 'StompKit/SKSocket/SKSocket.h' s.requires_arc = true s.dependency 'CocoaAsyncSocket', '7.3.4' s.dependency 'SocketRocket', '0.3.1-beta2' From e744f09a06626e46c4ced7a7c742e51a51550b4d Mon Sep 17 00:00:00 2001 From: Massimo Nicolardi Date: Tue, 1 Sep 2015 12:14:59 +0200 Subject: [PATCH 14/14] Fix --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6451b44..cb331b2 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ STOMPClient *client = [[STOMPClient alloc] initWithHost:@"localhost" [client connectWithLogin:@"mylogin" passcode:@"mypassword" completionHandler:^(STOMPFrame *_, NSError *error) { - if (err) { + if (error) { NSLog(@"%@", error); return; } @@ -66,7 +66,7 @@ STOMPClient *client = [[STOMPClient alloc] initWithHost:@"localhost" [client connectWithLogin:@"mylogin" passcode:@"mypassword" completionHandler:^(STOMPFrame *_, NSError *error) { - if (err) { + if (error) { NSLog(@"%@", error); return; }