├── .gitignore ├── LICENSE ├── PKJSONSocket.podspec ├── PKJSONSocket.xcodeproj ├── project.pbxproj └── project.xcworkspace │ └── contents.xcworkspacedata ├── PKJSONSocket.xcworkspace └── contents.xcworkspacedata ├── PKJSONSocket ├── Classes │ ├── PKJSONSocket.h │ ├── PKJSONSocket.m │ ├── PKJSONSocketDelegate.h │ ├── PKJSONSocketMessage.h │ └── PKJSONSocketMessage.m ├── Other Sources │ └── PKJSONSocket-Prefix.pch └── Resources │ └── PKJSONSocket-Info.plist ├── Podfile ├── Podfile.lock └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | .DS_Store 3 | */build/* 4 | *.pbxuser 5 | !default.pbxuser 6 | *.mode1v3 7 | !default.mode1v3 8 | *.mode2v3 9 | !default.mode2v3 10 | *.perspectivev3 11 | !default.perspectivev3 12 | xcuserdata 13 | profile 14 | *.moved-aside 15 | DerivedData 16 | .idea/ 17 | *.hmap 18 | *.xccheckout 19 | 20 | #CocoaPods 21 | Pods 22 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 Philip Kluz 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /PKJSONSocket.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |spec| 2 | 3 | spec.name = 'PKJSONSocket' 4 | spec.version = '0.0.2' 5 | spec.authors = { 'Philip Kluz' => 'philip.kluz@zuui.org' } 6 | spec.homepage = 'https://github.com/pkluz/PKJSONSocket' 7 | spec.summary = 'Simplified socket networking based on CocoaAsynSocket. Enabling direct JSON messaging between devices.' 8 | spec.source = { :git => 'https://github.com/pkluz/PKJSONSocket.git', :tag => "v#{spec.version}" } 9 | spec.license = { :type => 'MIT', :file => 'LICENSE' } 10 | 11 | spec.dependency 'CocoaAsyncSocket', '~> 7.3.2' 12 | 13 | spec.requires_arc = true 14 | 15 | spec.ios.deployment_target = '6.0' 16 | spec.ios.source_files = 'PKJSONSocket/Classes/*.{h,m}' 17 | 18 | spec.osx.deployment_target = '10.8' 19 | spec.osx.source_files = 'PKJSONSocket/Classes/*.{h,m}' 20 | 21 | end 22 | -------------------------------------------------------------------------------- /PKJSONSocket.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 27D2794EF9E648F2BCE028CB /* libPods-libPKJSONSocket.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FDB6DE6C270A4364916656AA /* libPods-libPKJSONSocket.a */; }; 11 | 4EDB417D0B9A417D8DD2BD66 /* libPods-PKJSONSocketFramework.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 8AEE8AD022C24324937D3D48 /* libPods-PKJSONSocketFramework.a */; }; 12 | F90833AF180EFD420018C44E /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F9EBD9B2180EDFCD00711269 /* Foundation.framework */; }; 13 | F90833D1180EFE060018C44E /* PKJSONSocket.m in Sources */ = {isa = PBXBuildFile; fileRef = F9EBD9DF180EE15000711269 /* PKJSONSocket.m */; }; 14 | F90833D2180EFE080018C44E /* PKJSONSocketMessage.m in Sources */ = {isa = PBXBuildFile; fileRef = F90833A5180EFAC40018C44E /* PKJSONSocketMessage.m */; }; 15 | F9C1C3DD180F19D900A206AC /* PKJSONSocket.m in Sources */ = {isa = PBXBuildFile; fileRef = F9EBD9DF180EE15000711269 /* PKJSONSocket.m */; }; 16 | F9C1C3DE180F19DE00A206AC /* PKJSONSocketMessage.m in Sources */ = {isa = PBXBuildFile; fileRef = F90833A5180EFAC40018C44E /* PKJSONSocketMessage.m */; }; 17 | F9C1C3DF180F19E300A206AC /* PKJSONSocketMessage.h in Headers */ = {isa = PBXBuildFile; fileRef = F90833A4180EFAC40018C44E /* PKJSONSocketMessage.h */; settings = {ATTRIBUTES = (Public, ); }; }; 18 | F9C1C3E0180F19E500A206AC /* PKJSONSocketDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = F9C1C3AE180F140D00A206AC /* PKJSONSocketDelegate.h */; settings = {ATTRIBUTES = (Public, ); }; }; 19 | F9C1C3E1180F19EC00A206AC /* PKJSONSocket.h in Headers */ = {isa = PBXBuildFile; fileRef = F9EBD9DE180EE15000711269 /* PKJSONSocket.h */; settings = {ATTRIBUTES = (Public, ); }; }; 20 | /* End PBXBuildFile section */ 21 | 22 | /* Begin PBXCopyFilesBuildPhase section */ 23 | F90833AC180EFD420018C44E /* CopyFiles */ = { 24 | isa = PBXCopyFilesBuildPhase; 25 | buildActionMask = 2147483647; 26 | dstPath = "include/$(PRODUCT_NAME)"; 27 | dstSubfolderSpec = 16; 28 | files = ( 29 | ); 30 | runOnlyForDeploymentPostprocessing = 0; 31 | }; 32 | /* End PBXCopyFilesBuildPhase section */ 33 | 34 | /* Begin PBXFileReference section */ 35 | 04B7905DF5DB45D09687075F /* Pods-libPKJSONSocket.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-libPKJSONSocket.xcconfig"; path = "Pods/Pods-libPKJSONSocket.xcconfig"; sourceTree = SOURCE_ROOT; }; 36 | 23731CDA1D8549259486F68F /* Pods-PKJSONSocketFramework.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-PKJSONSocketFramework.xcconfig"; path = "Pods/Pods-PKJSONSocketFramework.xcconfig"; sourceTree = SOURCE_ROOT; }; 37 | 8AEE8AD022C24324937D3D48 /* libPods-PKJSONSocketFramework.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-PKJSONSocketFramework.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 38 | F90833A4180EFAC40018C44E /* PKJSONSocketMessage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PKJSONSocketMessage.h; sourceTree = ""; }; 39 | F90833A5180EFAC40018C44E /* PKJSONSocketMessage.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PKJSONSocketMessage.m; sourceTree = ""; }; 40 | F90833AE180EFD420018C44E /* liblibPKJSONSocket.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = liblibPKJSONSocket.a; sourceTree = BUILT_PRODUCTS_DIR; }; 41 | F9C1C3AE180F140D00A206AC /* PKJSONSocketDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PKJSONSocketDelegate.h; sourceTree = ""; }; 42 | F9C1C3B4180F15FF00A206AC /* PKJSONSocketFramework.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = PKJSONSocketFramework.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 43 | F9EBD9B2180EDFCD00711269 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; 44 | F9EBD9C3180EDFD000711269 /* XCTest.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = XCTest.framework; path = Library/Frameworks/XCTest.framework; sourceTree = DEVELOPER_DIR; }; 45 | F9EBD9DE180EE15000711269 /* PKJSONSocket.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PKJSONSocket.h; sourceTree = ""; }; 46 | F9EBD9DF180EE15000711269 /* PKJSONSocket.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PKJSONSocket.m; sourceTree = ""; }; 47 | F9EBD9E1180EE15000711269 /* PKJSONSocket-Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "PKJSONSocket-Prefix.pch"; sourceTree = ""; }; 48 | F9EBD9E3180EE15000711269 /* PKJSONSocket-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "PKJSONSocket-Info.plist"; sourceTree = ""; }; 49 | FDB6DE6C270A4364916656AA /* libPods-libPKJSONSocket.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-libPKJSONSocket.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 50 | /* End PBXFileReference section */ 51 | 52 | /* Begin PBXFrameworksBuildPhase section */ 53 | F90833AB180EFD420018C44E /* Frameworks */ = { 54 | isa = PBXFrameworksBuildPhase; 55 | buildActionMask = 2147483647; 56 | files = ( 57 | F90833AF180EFD420018C44E /* Foundation.framework in Frameworks */, 58 | 27D2794EF9E648F2BCE028CB /* libPods-libPKJSONSocket.a in Frameworks */, 59 | ); 60 | runOnlyForDeploymentPostprocessing = 0; 61 | }; 62 | F9C1C3B0180F15FF00A206AC /* Frameworks */ = { 63 | isa = PBXFrameworksBuildPhase; 64 | buildActionMask = 2147483647; 65 | files = ( 66 | 4EDB417D0B9A417D8DD2BD66 /* libPods-PKJSONSocketFramework.a in Frameworks */, 67 | ); 68 | runOnlyForDeploymentPostprocessing = 0; 69 | }; 70 | /* End PBXFrameworksBuildPhase section */ 71 | 72 | /* Begin PBXGroup section */ 73 | F9EBD9A4180EDFCD00711269 = { 74 | isa = PBXGroup; 75 | children = ( 76 | F9EBD9B4180EDFCD00711269 /* PKJSONSocket */, 77 | F9EBD9B1180EDFCD00711269 /* Frameworks */, 78 | F9EBD9B0180EDFCD00711269 /* Products */, 79 | 23731CDA1D8549259486F68F /* Pods-PKJSONSocketFramework.xcconfig */, 80 | 04B7905DF5DB45D09687075F /* Pods-libPKJSONSocket.xcconfig */, 81 | ); 82 | sourceTree = ""; 83 | }; 84 | F9EBD9B0180EDFCD00711269 /* Products */ = { 85 | isa = PBXGroup; 86 | children = ( 87 | F90833AE180EFD420018C44E /* liblibPKJSONSocket.a */, 88 | F9C1C3B4180F15FF00A206AC /* PKJSONSocketFramework.framework */, 89 | ); 90 | name = Products; 91 | sourceTree = ""; 92 | }; 93 | F9EBD9B1180EDFCD00711269 /* Frameworks */ = { 94 | isa = PBXGroup; 95 | children = ( 96 | F9EBD9B2180EDFCD00711269 /* Foundation.framework */, 97 | F9EBD9C3180EDFD000711269 /* XCTest.framework */, 98 | 8AEE8AD022C24324937D3D48 /* libPods-PKJSONSocketFramework.a */, 99 | FDB6DE6C270A4364916656AA /* libPods-libPKJSONSocket.a */, 100 | ); 101 | name = Frameworks; 102 | sourceTree = ""; 103 | }; 104 | F9EBD9B4180EDFCD00711269 /* PKJSONSocket */ = { 105 | isa = PBXGroup; 106 | children = ( 107 | F9EBD9DD180EE15000711269 /* Classes */, 108 | F9EBD9E0180EE15000711269 /* Other Sources */, 109 | F9EBD9E2180EE15000711269 /* Resources */, 110 | ); 111 | path = PKJSONSocket; 112 | sourceTree = ""; 113 | }; 114 | F9EBD9DD180EE15000711269 /* Classes */ = { 115 | isa = PBXGroup; 116 | children = ( 117 | F9EBD9DE180EE15000711269 /* PKJSONSocket.h */, 118 | F9EBD9DF180EE15000711269 /* PKJSONSocket.m */, 119 | F9C1C3AE180F140D00A206AC /* PKJSONSocketDelegate.h */, 120 | F90833A4180EFAC40018C44E /* PKJSONSocketMessage.h */, 121 | F90833A5180EFAC40018C44E /* PKJSONSocketMessage.m */, 122 | ); 123 | path = Classes; 124 | sourceTree = ""; 125 | }; 126 | F9EBD9E0180EE15000711269 /* Other Sources */ = { 127 | isa = PBXGroup; 128 | children = ( 129 | F9EBD9E1180EE15000711269 /* PKJSONSocket-Prefix.pch */, 130 | ); 131 | path = "Other Sources"; 132 | sourceTree = ""; 133 | }; 134 | F9EBD9E2180EE15000711269 /* Resources */ = { 135 | isa = PBXGroup; 136 | children = ( 137 | F9EBD9E3180EE15000711269 /* PKJSONSocket-Info.plist */, 138 | ); 139 | path = Resources; 140 | sourceTree = ""; 141 | }; 142 | /* End PBXGroup section */ 143 | 144 | /* Begin PBXHeadersBuildPhase section */ 145 | F9C1C3B1180F15FF00A206AC /* Headers */ = { 146 | isa = PBXHeadersBuildPhase; 147 | buildActionMask = 2147483647; 148 | files = ( 149 | F9C1C3DF180F19E300A206AC /* PKJSONSocketMessage.h in Headers */, 150 | F9C1C3E0180F19E500A206AC /* PKJSONSocketDelegate.h in Headers */, 151 | F9C1C3E1180F19EC00A206AC /* PKJSONSocket.h in Headers */, 152 | ); 153 | runOnlyForDeploymentPostprocessing = 0; 154 | }; 155 | /* End PBXHeadersBuildPhase section */ 156 | 157 | /* Begin PBXNativeTarget section */ 158 | F90833AD180EFD420018C44E /* libPKJSONSocket */ = { 159 | isa = PBXNativeTarget; 160 | buildConfigurationList = F90833CB180EFD420018C44E /* Build configuration list for PBXNativeTarget "libPKJSONSocket" */; 161 | buildPhases = ( 162 | 9344ADE179DD4F94B6E59845 /* Check Pods Manifest.lock */, 163 | F90833AA180EFD420018C44E /* Sources */, 164 | F90833AB180EFD420018C44E /* Frameworks */, 165 | F90833AC180EFD420018C44E /* CopyFiles */, 166 | 184EFDACC292427B8A5992DE /* Copy Pods Resources */, 167 | ); 168 | buildRules = ( 169 | ); 170 | dependencies = ( 171 | ); 172 | name = libPKJSONSocket; 173 | productName = PKJSONSocket; 174 | productReference = F90833AE180EFD420018C44E /* liblibPKJSONSocket.a */; 175 | productType = "com.apple.product-type.library.static"; 176 | }; 177 | F9C1C3B3180F15FF00A206AC /* PKJSONSocketFramework */ = { 178 | isa = PBXNativeTarget; 179 | buildConfigurationList = F9C1C3D7180F160000A206AC /* Build configuration list for PBXNativeTarget "PKJSONSocketFramework" */; 180 | buildPhases = ( 181 | B98FA01259F645029BCDE216 /* Check Pods Manifest.lock */, 182 | F9C1C3AF180F15FF00A206AC /* Sources */, 183 | F9C1C3B0180F15FF00A206AC /* Frameworks */, 184 | F9C1C3B1180F15FF00A206AC /* Headers */, 185 | 400ADD119AD34970B30FDA7F /* Copy Pods Resources */, 186 | ); 187 | buildRules = ( 188 | ); 189 | dependencies = ( 190 | ); 191 | name = PKJSONSocketFramework; 192 | productName = PKJSONSocketFramework; 193 | productReference = F9C1C3B4180F15FF00A206AC /* PKJSONSocketFramework.framework */; 194 | productType = "com.apple.product-type.framework"; 195 | }; 196 | /* End PBXNativeTarget section */ 197 | 198 | /* Begin PBXProject section */ 199 | F9EBD9A5180EDFCD00711269 /* Project object */ = { 200 | isa = PBXProject; 201 | attributes = { 202 | LastUpgradeCheck = 0500; 203 | ORGANIZATIONNAME = "zuui.org (Philip Kluz)"; 204 | }; 205 | buildConfigurationList = F9EBD9A8180EDFCD00711269 /* Build configuration list for PBXProject "PKJSONSocket" */; 206 | compatibilityVersion = "Xcode 3.2"; 207 | developmentRegion = English; 208 | hasScannedForEncodings = 0; 209 | knownRegions = ( 210 | en, 211 | ); 212 | mainGroup = F9EBD9A4180EDFCD00711269; 213 | productRefGroup = F9EBD9B0180EDFCD00711269 /* Products */; 214 | projectDirPath = ""; 215 | projectRoot = ""; 216 | targets = ( 217 | F90833AD180EFD420018C44E /* libPKJSONSocket */, 218 | F9C1C3B3180F15FF00A206AC /* PKJSONSocketFramework */, 219 | ); 220 | }; 221 | /* End PBXProject section */ 222 | 223 | /* Begin PBXShellScriptBuildPhase section */ 224 | 184EFDACC292427B8A5992DE /* Copy Pods Resources */ = { 225 | isa = PBXShellScriptBuildPhase; 226 | buildActionMask = 2147483647; 227 | files = ( 228 | ); 229 | inputPaths = ( 230 | ); 231 | name = "Copy Pods Resources"; 232 | outputPaths = ( 233 | ); 234 | runOnlyForDeploymentPostprocessing = 0; 235 | shellPath = /bin/sh; 236 | shellScript = "\"${SRCROOT}/Pods/Pods-libPKJSONSocket-resources.sh\"\n"; 237 | }; 238 | 400ADD119AD34970B30FDA7F /* Copy Pods Resources */ = { 239 | isa = PBXShellScriptBuildPhase; 240 | buildActionMask = 2147483647; 241 | files = ( 242 | ); 243 | inputPaths = ( 244 | ); 245 | name = "Copy Pods Resources"; 246 | outputPaths = ( 247 | ); 248 | runOnlyForDeploymentPostprocessing = 0; 249 | shellPath = /bin/sh; 250 | shellScript = "\"${SRCROOT}/Pods/Pods-PKJSONSocketFramework-resources.sh\"\n"; 251 | }; 252 | 9344ADE179DD4F94B6E59845 /* Check Pods Manifest.lock */ = { 253 | isa = PBXShellScriptBuildPhase; 254 | buildActionMask = 2147483647; 255 | files = ( 256 | ); 257 | inputPaths = ( 258 | ); 259 | name = "Check Pods Manifest.lock"; 260 | outputPaths = ( 261 | ); 262 | runOnlyForDeploymentPostprocessing = 0; 263 | shellPath = /bin/sh; 264 | shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n"; 265 | }; 266 | B98FA01259F645029BCDE216 /* Check Pods Manifest.lock */ = { 267 | isa = PBXShellScriptBuildPhase; 268 | buildActionMask = 2147483647; 269 | files = ( 270 | ); 271 | inputPaths = ( 272 | ); 273 | name = "Check Pods Manifest.lock"; 274 | outputPaths = ( 275 | ); 276 | runOnlyForDeploymentPostprocessing = 0; 277 | shellPath = /bin/sh; 278 | shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n"; 279 | }; 280 | /* End PBXShellScriptBuildPhase section */ 281 | 282 | /* Begin PBXSourcesBuildPhase section */ 283 | F90833AA180EFD420018C44E /* Sources */ = { 284 | isa = PBXSourcesBuildPhase; 285 | buildActionMask = 2147483647; 286 | files = ( 287 | F90833D1180EFE060018C44E /* PKJSONSocket.m in Sources */, 288 | F90833D2180EFE080018C44E /* PKJSONSocketMessage.m in Sources */, 289 | ); 290 | runOnlyForDeploymentPostprocessing = 0; 291 | }; 292 | F9C1C3AF180F15FF00A206AC /* Sources */ = { 293 | isa = PBXSourcesBuildPhase; 294 | buildActionMask = 2147483647; 295 | files = ( 296 | F9C1C3DE180F19DE00A206AC /* PKJSONSocketMessage.m in Sources */, 297 | F9C1C3DD180F19D900A206AC /* PKJSONSocket.m in Sources */, 298 | ); 299 | runOnlyForDeploymentPostprocessing = 0; 300 | }; 301 | /* End PBXSourcesBuildPhase section */ 302 | 303 | /* Begin XCBuildConfiguration section */ 304 | F90833CC180EFD420018C44E /* Debug */ = { 305 | isa = XCBuildConfiguration; 306 | baseConfigurationReference = 04B7905DF5DB45D09687075F /* Pods-libPKJSONSocket.xcconfig */; 307 | buildSettings = { 308 | ARCHS = "$(ARCHS_STANDARD_INCLUDING_64_BIT)"; 309 | DSTROOT = /tmp/PKJSONSocket.dst; 310 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 311 | GCC_PREFIX_HEADER = "PKJSONSocket/Other Sources/PKJSONSocket-Prefix.pch"; 312 | GCC_PREPROCESSOR_DEFINITIONS = ( 313 | "DEBUG=1", 314 | "$(inherited)", 315 | ); 316 | OTHER_LDFLAGS = "$(inherited)"; 317 | PRODUCT_NAME = "$(TARGET_NAME)"; 318 | SKIP_INSTALL = YES; 319 | }; 320 | name = Debug; 321 | }; 322 | F90833CD180EFD420018C44E /* Release */ = { 323 | isa = XCBuildConfiguration; 324 | baseConfigurationReference = 04B7905DF5DB45D09687075F /* Pods-libPKJSONSocket.xcconfig */; 325 | buildSettings = { 326 | ARCHS = "$(ARCHS_STANDARD_INCLUDING_64_BIT)"; 327 | DSTROOT = /tmp/PKJSONSocket.dst; 328 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 329 | GCC_PREFIX_HEADER = "PKJSONSocket/Other Sources/PKJSONSocket-Prefix.pch"; 330 | OTHER_LDFLAGS = "$(inherited)"; 331 | PRODUCT_NAME = "$(TARGET_NAME)"; 332 | SKIP_INSTALL = YES; 333 | }; 334 | name = Release; 335 | }; 336 | F9C1C3D8180F160000A206AC /* Debug */ = { 337 | isa = XCBuildConfiguration; 338 | baseConfigurationReference = 23731CDA1D8549259486F68F /* Pods-PKJSONSocketFramework.xcconfig */; 339 | buildSettings = { 340 | COMBINE_HIDPI_IMAGES = YES; 341 | DYLIB_COMPATIBILITY_VERSION = 1; 342 | DYLIB_CURRENT_VERSION = 1; 343 | FRAMEWORK_SEARCH_PATHS = ( 344 | "$(inherited)", 345 | "$(DEVELOPER_FRAMEWORKS_DIR)", 346 | ); 347 | FRAMEWORK_VERSION = A; 348 | GCC_ENABLE_OBJC_EXCEPTIONS = YES; 349 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 350 | GCC_PREFIX_HEADER = "PKJSONSocket/Other Sources/PKJSONSocket-Prefix.pch"; 351 | GCC_PREPROCESSOR_DEFINITIONS = ( 352 | "DEBUG=1", 353 | "$(inherited)", 354 | ); 355 | INFOPLIST_FILE = "PKJSONSocket/Resources/PKJSONSocket-Info.plist"; 356 | MACOSX_DEPLOYMENT_TARGET = 10.8; 357 | OTHER_LDFLAGS = "$(inherited)"; 358 | PRODUCT_NAME = "$(TARGET_NAME)"; 359 | SDKROOT = macosx; 360 | WRAPPER_EXTENSION = framework; 361 | }; 362 | name = Debug; 363 | }; 364 | F9C1C3D9180F160000A206AC /* Release */ = { 365 | isa = XCBuildConfiguration; 366 | baseConfigurationReference = 23731CDA1D8549259486F68F /* Pods-PKJSONSocketFramework.xcconfig */; 367 | buildSettings = { 368 | COMBINE_HIDPI_IMAGES = YES; 369 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 370 | DYLIB_COMPATIBILITY_VERSION = 1; 371 | DYLIB_CURRENT_VERSION = 1; 372 | FRAMEWORK_SEARCH_PATHS = ( 373 | "$(inherited)", 374 | "$(DEVELOPER_FRAMEWORKS_DIR)", 375 | ); 376 | FRAMEWORK_VERSION = A; 377 | GCC_ENABLE_OBJC_EXCEPTIONS = YES; 378 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 379 | GCC_PREFIX_HEADER = "PKJSONSocket/Other Sources/PKJSONSocket-Prefix.pch"; 380 | INFOPLIST_FILE = "PKJSONSocket/Resources/PKJSONSocket-Info.plist"; 381 | MACOSX_DEPLOYMENT_TARGET = 10.8; 382 | OTHER_LDFLAGS = "$(inherited)"; 383 | PRODUCT_NAME = "$(TARGET_NAME)"; 384 | SDKROOT = macosx; 385 | WRAPPER_EXTENSION = framework; 386 | }; 387 | name = Release; 388 | }; 389 | F9EBD9D5180EDFD100711269 /* Debug */ = { 390 | isa = XCBuildConfiguration; 391 | buildSettings = { 392 | ALWAYS_SEARCH_USER_PATHS = NO; 393 | ARCHS = "$(ARCHS_STANDARD_INCLUDING_64_BIT)"; 394 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 395 | CLANG_CXX_LIBRARY = "libc++"; 396 | CLANG_ENABLE_MODULES = YES; 397 | CLANG_ENABLE_OBJC_ARC = YES; 398 | CLANG_WARN_BOOL_CONVERSION = YES; 399 | CLANG_WARN_CONSTANT_CONVERSION = YES; 400 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 401 | CLANG_WARN_EMPTY_BODY = YES; 402 | CLANG_WARN_ENUM_CONVERSION = YES; 403 | CLANG_WARN_INT_CONVERSION = YES; 404 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 405 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 406 | COPY_PHASE_STRIP = NO; 407 | GCC_C_LANGUAGE_STANDARD = gnu99; 408 | GCC_DYNAMIC_NO_PIC = NO; 409 | GCC_OPTIMIZATION_LEVEL = 0; 410 | GCC_PREPROCESSOR_DEFINITIONS = ( 411 | "DEBUG=1", 412 | "$(inherited)", 413 | ); 414 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 415 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 416 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 417 | GCC_WARN_UNDECLARED_SELECTOR = YES; 418 | GCC_WARN_UNINITIALIZED_AUTOS = YES; 419 | GCC_WARN_UNUSED_FUNCTION = YES; 420 | GCC_WARN_UNUSED_VARIABLE = YES; 421 | IPHONEOS_DEPLOYMENT_TARGET = 7.0; 422 | MACOSX_DEPLOYMENT_TARGET = 10.8; 423 | ONLY_ACTIVE_ARCH = YES; 424 | SDKROOT = iphoneos; 425 | }; 426 | name = Debug; 427 | }; 428 | F9EBD9D6180EDFD100711269 /* Release */ = { 429 | isa = XCBuildConfiguration; 430 | buildSettings = { 431 | ALWAYS_SEARCH_USER_PATHS = NO; 432 | ARCHS = "$(ARCHS_STANDARD_INCLUDING_64_BIT)"; 433 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 434 | CLANG_CXX_LIBRARY = "libc++"; 435 | CLANG_ENABLE_MODULES = YES; 436 | CLANG_ENABLE_OBJC_ARC = YES; 437 | CLANG_WARN_BOOL_CONVERSION = YES; 438 | CLANG_WARN_CONSTANT_CONVERSION = YES; 439 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 440 | CLANG_WARN_EMPTY_BODY = YES; 441 | CLANG_WARN_ENUM_CONVERSION = YES; 442 | CLANG_WARN_INT_CONVERSION = YES; 443 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 444 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 445 | COPY_PHASE_STRIP = YES; 446 | ENABLE_NS_ASSERTIONS = NO; 447 | GCC_C_LANGUAGE_STANDARD = gnu99; 448 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 449 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 450 | GCC_WARN_UNDECLARED_SELECTOR = YES; 451 | GCC_WARN_UNINITIALIZED_AUTOS = YES; 452 | GCC_WARN_UNUSED_FUNCTION = YES; 453 | GCC_WARN_UNUSED_VARIABLE = YES; 454 | IPHONEOS_DEPLOYMENT_TARGET = 7.0; 455 | MACOSX_DEPLOYMENT_TARGET = 10.8; 456 | SDKROOT = iphoneos; 457 | VALIDATE_PRODUCT = YES; 458 | }; 459 | name = Release; 460 | }; 461 | /* End XCBuildConfiguration section */ 462 | 463 | /* Begin XCConfigurationList section */ 464 | F90833CB180EFD420018C44E /* Build configuration list for PBXNativeTarget "libPKJSONSocket" */ = { 465 | isa = XCConfigurationList; 466 | buildConfigurations = ( 467 | F90833CC180EFD420018C44E /* Debug */, 468 | F90833CD180EFD420018C44E /* Release */, 469 | ); 470 | defaultConfigurationIsVisible = 0; 471 | defaultConfigurationName = Release; 472 | }; 473 | F9C1C3D7180F160000A206AC /* Build configuration list for PBXNativeTarget "PKJSONSocketFramework" */ = { 474 | isa = XCConfigurationList; 475 | buildConfigurations = ( 476 | F9C1C3D8180F160000A206AC /* Debug */, 477 | F9C1C3D9180F160000A206AC /* Release */, 478 | ); 479 | defaultConfigurationIsVisible = 0; 480 | defaultConfigurationName = Release; 481 | }; 482 | F9EBD9A8180EDFCD00711269 /* Build configuration list for PBXProject "PKJSONSocket" */ = { 483 | isa = XCConfigurationList; 484 | buildConfigurations = ( 485 | F9EBD9D5180EDFD100711269 /* Debug */, 486 | F9EBD9D6180EDFD100711269 /* Release */, 487 | ); 488 | defaultConfigurationIsVisible = 0; 489 | defaultConfigurationName = Release; 490 | }; 491 | /* End XCConfigurationList section */ 492 | }; 493 | rootObject = F9EBD9A5180EDFCD00711269 /* Project object */; 494 | } 495 | -------------------------------------------------------------------------------- /PKJSONSocket.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /PKJSONSocket.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /PKJSONSocket/Classes/PKJSONSocket.h: -------------------------------------------------------------------------------- 1 | /* 2 | PKJSONSocket > PKJSONSocket.h 3 | Copyright (c) 2013 zuui.org (Philip Kluz). All rights reserved. 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2013 Philip Kluz 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy of 10 | this software and associated documentation files (the "Software"), to deal in 11 | the Software without restriction, including without limitation the rights to 12 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 13 | the Software, and to permit persons to whom the Software is furnished to do so, 14 | subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in all 17 | copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 21 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 22 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 23 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 24 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 | */ 26 | 27 | @import Foundation; 28 | @import CocoaAsyncSocket; 29 | 30 | #import "PKJSONSocketDelegate.h" 31 | #import "PKJSONSocketMessage.h" 32 | 33 | typedef void (^PKJSONSocketConnectHandler)(NSError *error); 34 | 35 | @interface PKJSONSocket : NSObject 36 | 37 | #pragma mark - Properties 38 | @property (nonatomic, weak, readwrite) id delegate; 39 | @property (nonatomic, assign, readwrite, getter = isConnected) BOOL connected; 40 | 41 | #pragma mark - Methods 42 | /* 43 | Initializes a new socket and sets the delegate. 44 | 45 | @param delegate A delegate object conforming to the PKJSONSocketDelegate protocol. 46 | */ 47 | + (instancetype)socketWithDelegate:(id)delegate; 48 | 49 | /* 50 | Connects to the given, identified by IP. 51 | 52 | @param IP The IP of the host to connect to. 53 | @param port The port to use for the connection. 54 | @param error Pointer to an error object in case something went wrong. 55 | */ 56 | - (void)connectToHost:(NSString *)IP onPort:(uint16_t)port error:(NSError *__autoreleasing *)error; 57 | 58 | /* 59 | Allows the socket to listen for new incoming connections. Note: connectToHost:onPort:error: and 60 | listenOnPort:error: are mutually exclusive. I.e. your socket it either a passive (listening) socket 61 | or an active (connecting) socket. 62 | 63 | @param IP The port to accept connections on. Root priviledges required for certain ports. 64 | @param error Pointer to an error object in case something went wrong. 65 | */ 66 | - (void)listenOnPort:(uint16_t)port error:(NSError *__autoreleasing *)error; 67 | 68 | /* 69 | Disconnects the socket. 70 | */ 71 | - (void)disconnect; 72 | 73 | /* 74 | Sends a message down the wire to the host the socket is connected to. CRLF separated messages. 75 | 76 | @param message The message that's going to be sent. 77 | */ 78 | - (void)send:(PKJSONSocketMessage *)message; 79 | 80 | @end 81 | -------------------------------------------------------------------------------- /PKJSONSocket/Classes/PKJSONSocket.m: -------------------------------------------------------------------------------- 1 | /* 2 | PKJSONSocket > PKJSONSocket.m 3 | Copyright (c) 2013 zuui.org (Philip Kluz). All rights reserved. 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2013 Philip Kluz 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy of 10 | this software and associated documentation files (the "Software"), to deal in 11 | the Software without restriction, including without limitation the rights to 12 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 13 | the Software, and to permit persons to whom the Software is furnished to do so, 14 | subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in all 17 | copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 21 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 22 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 23 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 24 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 | */ 26 | 27 | #import "PKJSONSocket.h" 28 | 29 | @interface PKJSONSocket () 30 | 31 | @property (nonatomic, strong, readwrite) GCDAsyncSocket *internalSocket; 32 | 33 | @end 34 | 35 | @implementation PKJSONSocket 36 | 37 | #pragma mark - Initialization 38 | 39 | + (instancetype)socketWithDelegate:(id)delegate 40 | { 41 | return [[[self class] alloc] initWithDelegate:delegate]; 42 | } 43 | 44 | + (instancetype)socketWithGCDAsyncSocket:(GCDAsyncSocket *)socket 45 | { 46 | return [[[self class] alloc] initWithGCDAsyncSocket:socket]; 47 | } 48 | 49 | - (instancetype)initWithDelegate:(id)delegate 50 | { 51 | self = [super init]; 52 | 53 | if (self) 54 | { 55 | self.delegate = delegate; 56 | } 57 | 58 | return self; 59 | } 60 | 61 | - (instancetype)initWithGCDAsyncSocket:(GCDAsyncSocket *)socket 62 | { 63 | self = [super init]; 64 | 65 | if (self) 66 | { 67 | self.internalSocket = socket; 68 | } 69 | 70 | return self; 71 | } 72 | 73 | #pragma mark - API 74 | 75 | - (void)connectToHost:(NSString *)IP 76 | onPort:(uint16_t)port 77 | error:(NSError *__autoreleasing *)error 78 | { 79 | if (!self.internalSocket) 80 | { 81 | self.internalSocket = [[GCDAsyncSocket alloc] initWithDelegate:self 82 | delegateQueue:dispatch_get_main_queue()]; 83 | [self.internalSocket connectToHost:IP onPort:port error:error]; 84 | } 85 | } 86 | 87 | - (void)disconnect 88 | { 89 | [self.internalSocket disconnect]; 90 | } 91 | 92 | - (void)listenOnPort:(uint16_t)port error:(NSError *__autoreleasing *)error 93 | { 94 | if (!self.internalSocket) 95 | { 96 | self.internalSocket = [[GCDAsyncSocket alloc] initWithDelegate:self 97 | delegateQueue:dispatch_get_main_queue()]; 98 | [self.internalSocket acceptOnPort:port error:error]; 99 | } 100 | } 101 | 102 | - (void)send:(PKJSONSocketMessage *)message 103 | { 104 | [self.internalSocket writeData:[message dataRepresentation] 105 | withTimeout:-1 106 | tag:0]; 107 | [self.internalSocket writeData:[GCDAsyncSocket CRLFData] 108 | withTimeout:-1 109 | tag:0]; 110 | } 111 | 112 | - (BOOL)isConnected 113 | { 114 | return self.internalSocket.isConnected; 115 | } 116 | 117 | #pragma mark - Helper 118 | 119 | - (void)readNextMessage 120 | { 121 | [self.internalSocket readDataToData:[GCDAsyncSocket CRLFData] 122 | withTimeout:-1 123 | tag:0]; 124 | } 125 | 126 | #pragma mark - GCDAsyncSocketDelegate 127 | 128 | - (void)socket:(GCDAsyncSocket *)socket didAcceptNewSocket:(GCDAsyncSocket *)newInternalSocket 129 | { 130 | if (socket != self.internalSocket) 131 | { 132 | return; 133 | } 134 | 135 | PKJSONSocket *newSocket = [PKJSONSocket socketWithGCDAsyncSocket:newInternalSocket]; 136 | newInternalSocket.delegate = newSocket; 137 | 138 | if ([self.delegate respondsToSelector:@selector(socket:didAcceptNewSocket:)]) 139 | { 140 | dispatch_async(dispatch_get_main_queue(), ^{ 141 | [self.delegate socket:self didAcceptNewSocket:newSocket]; 142 | }); 143 | } 144 | 145 | [newSocket readNextMessage]; 146 | } 147 | 148 | - (void)socket:(GCDAsyncSocket *)socket didConnectToHost:(NSString *)host port:(uint16_t)port 149 | { 150 | if (socket != self.internalSocket) 151 | { 152 | return; 153 | } 154 | 155 | if ([self.delegate respondsToSelector:@selector(socket:didConnectToHost:)]) 156 | { 157 | dispatch_async(dispatch_get_main_queue(), ^{ 158 | [self.delegate socket:self didConnectToHost:host]; 159 | }); 160 | } 161 | 162 | [self readNextMessage]; 163 | } 164 | 165 | - (void)socketDidDisconnect:(GCDAsyncSocket *)socket withError:(NSError *)error 166 | { 167 | if (socket != self.internalSocket) 168 | { 169 | return; 170 | } 171 | 172 | if ([self.delegate respondsToSelector:@selector(socket:didDisconnectWithError:)]) 173 | { 174 | [self.delegate socket:self didDisconnectWithError:error]; 175 | } 176 | 177 | self.internalSocket.delegate = nil; 178 | self.internalSocket = nil; 179 | } 180 | 181 | - (void)socket:(GCDAsyncSocket *)socket didReadData:(NSData *)data withTag:(long)tag 182 | { 183 | if (socket != self.internalSocket) 184 | { 185 | return; 186 | } 187 | 188 | dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ 189 | 190 | PKJSONSocketMessage *message = [PKJSONSocketMessage messageWithData:data]; 191 | 192 | if (message && [self.delegate respondsToSelector:@selector(socket:didReceiveMessage:)]) 193 | { 194 | dispatch_async(dispatch_get_main_queue(), ^{ 195 | [self.delegate socket:self didReceiveMessage:message]; 196 | }); 197 | } 198 | }); 199 | 200 | [self readNextMessage]; 201 | } 202 | 203 | @end 204 | -------------------------------------------------------------------------------- /PKJSONSocket/Classes/PKJSONSocketDelegate.h: -------------------------------------------------------------------------------- 1 | /* 2 | PKJSONSocket > PKJSONSocketDelegate.h 3 | Copyright (c) 2013 zuui.org (Philip Kluz). All rights reserved. 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2013 Philip Kluz 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy of 10 | this software and associated documentation files (the "Software"), to deal in 11 | the Software without restriction, including without limitation the rights to 12 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 13 | the Software, and to permit persons to whom the Software is furnished to do so, 14 | subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in all 17 | copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 21 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 22 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 23 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 24 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 | */ 26 | 27 | #import 28 | 29 | @class PKJSONSocket; 30 | @class PKJSONSocketMessage; 31 | 32 | @protocol PKJSONSocketDelegate 33 | 34 | @optional 35 | /* 36 | This method is invoked on your delegate whenever a listening (passive) socket accepts a new incoming 37 | connection. Please keep in mind that you need to retain the newSocket in some way or it'll be released. 38 | 39 | @param socket The listening socket. 40 | @param newSocket The newly spawned socket connection. 41 | */ 42 | - (void)socket:(PKJSONSocket *)socket didAcceptNewSocket:(PKJSONSocket *)newSocket; 43 | 44 | /* 45 | This method is invoked on your delegate when the connectToHost:onPort:error: method established a 46 | connection successfully. 47 | 48 | @param socket The relevant socket. 49 | @param host The host the socket established a connection with. 50 | */ 51 | - (void)socket:(PKJSONSocket *)socket didConnectToHost:(NSString *)host; 52 | 53 | /* 54 | This method is invoked on your delegate when the sockets connection is dropped. 55 | 56 | @param socket The relevant socket. 57 | @param error Pointer to an error object containing more information regarding the disconnect. 58 | */ 59 | - (void)socket:(PKJSONSocket *)socket didDisconnectWithError:(NSError *)error; 60 | 61 | /* 62 | This method is invoked on your delegate whenever the socket receives a message. 63 | 64 | @param socket The relevant socket. 65 | @param message The message that was received. 66 | */ 67 | - (void)socket:(PKJSONSocket *)socket didReceiveMessage:(PKJSONSocketMessage *)dictionary; 68 | 69 | @end 70 | -------------------------------------------------------------------------------- /PKJSONSocket/Classes/PKJSONSocketMessage.h: -------------------------------------------------------------------------------- 1 | /* 2 | PKJSONSocket > PKJSONSocketMessage.h 3 | Copyright (c) 2013 zuui.org (Philip Kluz). All rights reserved. 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2013 Philip Kluz 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy of 10 | this software and associated documentation files (the "Software"), to deal in 11 | the Software without restriction, including without limitation the rights to 12 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 13 | the Software, and to permit persons to whom the Software is furnished to do so, 14 | subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in all 17 | copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 21 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 22 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 23 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 24 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 | */ 26 | 27 | #import 28 | 29 | @interface PKJSONSocketMessage : NSObject 30 | 31 | /* 32 | This method is used when initializing a message manually in order for it to be dispatched via the socket. 33 | */ 34 | + (instancetype)messageWithDictionary:(NSDictionary *)dict; 35 | 36 | /* 37 | This method is used by the PKJSONSocket in order to return a message that was received as data. 38 | */ 39 | + (instancetype)messageWithData:(NSData *)data; 40 | 41 | - (NSDictionary *)dictionaryRepresentation; 42 | - (NSData *)dataRepresentation; 43 | 44 | @end 45 | -------------------------------------------------------------------------------- /PKJSONSocket/Classes/PKJSONSocketMessage.m: -------------------------------------------------------------------------------- 1 | /* 2 | PKJSONSocket > PKJSONSocketMessage.m 3 | Copyright (c) 2013 zuui.org (Philip Kluz). All rights reserved. 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2013 Philip Kluz 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy of 10 | this software and associated documentation files (the "Software"), to deal in 11 | the Software without restriction, including without limitation the rights to 12 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 13 | the Software, and to permit persons to whom the Software is furnished to do so, 14 | subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in all 17 | copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 21 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 22 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 23 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 24 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 | */ 26 | 27 | #import "PKJSONSocketMessage.h" 28 | 29 | @interface PKJSONSocketMessage () 30 | 31 | #pragma mark - Properties 32 | @property (nonatomic, strong, readwrite) NSDictionary *dictionary; 33 | 34 | @end 35 | 36 | @implementation PKJSONSocketMessage 37 | 38 | #pragma mark - Initialization 39 | 40 | + (instancetype)messageWithData:(NSData *)data 41 | { 42 | return [[[self class] alloc] initWithData:data]; 43 | } 44 | 45 | + (instancetype)messageWithDictionary:(NSDictionary *)dict 46 | { 47 | return [[[self class] alloc] initWithDictionary:dict]; 48 | } 49 | 50 | - (instancetype)initWithDictionary:(NSDictionary *)dictionary 51 | { 52 | self = [super init]; 53 | 54 | if (self) 55 | { 56 | self.dictionary = dictionary; 57 | } 58 | 59 | return self; 60 | } 61 | 62 | - (instancetype)initWithData:(NSData *)data 63 | { 64 | id JSONObject = [NSJSONSerialization JSONObjectWithData:data 65 | options:0 66 | error:nil]; 67 | 68 | if ([JSONObject isKindOfClass:[NSDictionary class]]) 69 | { 70 | self = [super init]; 71 | 72 | if (self) 73 | { 74 | self.dictionary = JSONObject; 75 | } 76 | 77 | return self; 78 | } 79 | 80 | return nil; 81 | } 82 | 83 | #pragma mark - Accessors 84 | 85 | - (NSData *)dataRepresentation 86 | { 87 | return [NSJSONSerialization dataWithJSONObject:self.dictionaryRepresentation 88 | options:0 89 | error:nil]; 90 | } 91 | 92 | - (NSDictionary *)dictionaryRepresentation 93 | { 94 | return _dictionary; 95 | } 96 | 97 | @end 98 | -------------------------------------------------------------------------------- /PKJSONSocket/Other Sources/PKJSONSocket-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header 3 | // 4 | // The contents of this file are implicitly included at the beginning of every source file. 5 | // 6 | 7 | #ifdef __OBJC__ 8 | #import 9 | #endif 10 | -------------------------------------------------------------------------------- /PKJSONSocket/Resources/PKJSONSocket-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIconFile 10 | 11 | CFBundleIdentifier 12 | org.zuui.${PRODUCT_NAME:rfc1034identifier} 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | FMWK 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1 25 | NSPrincipalClass 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /Podfile: -------------------------------------------------------------------------------- 1 | workspace 'PKJSONSocket.xcworkspace' 2 | 3 | target 'libPKJSONSocket' do 4 | platform :ios, '6.0' 5 | pod 'CocoaAsyncSocket', '~> 7.3.2' 6 | end 7 | 8 | target 'PKJSONSocketFramework' do 9 | platform :osx, '10.8' 10 | pod 'CocoaAsyncSocket', '~> 7.3.2' 11 | end 12 | -------------------------------------------------------------------------------- /Podfile.lock: -------------------------------------------------------------------------------- 1 | PODS: 2 | - CocoaAsyncSocket (7.3.2) 3 | 4 | DEPENDENCIES: 5 | - CocoaAsyncSocket (~> 7.3.2) 6 | 7 | SPEC CHECKSUMS: 8 | CocoaAsyncSocket: 977404129ec8505fee1c3701956b769e3bb10ea7 9 | 10 | COCOAPODS: 0.24.0 11 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | #PKJSONSocket 2 | 3 | PKJSONSocket aims to simplify network communications. It's a delightful wrapper around _[CocoaAsyncSocket](https://github.com/robbiehanson/CocoaAsyncSocket)_, abstracting away complex data flow into an easy to use API. Instead of dealing with the bits and bytes yourself, PKJSONSocket offers you UTF-8 encoded JSON strings. 4 | 5 | ## Installation (CocoaPods) 6 | ``` 7 | pod 'PKJSONSocket' 8 | ``` 9 | 10 | ## Usage 11 | 12 | Simply `#import "PKJSONSocket.h"` and... 13 | 14 | - **Connect** to a remote host: 15 | 16 | ``` objective-c 17 | PKJSONSocket *socket = [PKJSONSocket socketWithDelegate:self]; 18 | [socket connectToHost:@"127.0.0.1" onPort:3333 error:nil]; 19 | ``` 20 | 21 | - **Listen** for incoming connections: 22 | ``` objective-c 23 | [socket listenOnPort:3333 error:nil]; 24 | ``` 25 | 26 | - Watch for **incoming data** by conforming to the `` protocol: 27 | ``` objective-c 28 | - (void)socket:(PKJSONSocket *)socket didReceiveMessage:(PKJSONSocketMessage *)msg 29 | { 30 | NSLog(@"Received: %@", [msg dictionaryRepresentation]); 31 | } 32 | ``` 33 | 34 | - **Send** messages down the wire: 35 | ``` objective-c 36 | NSDictionary *dict = @{ @"message" : @"The answer is 42." }; 37 | PKJSONSocketMessage *msg = [PKJSONSocketMessage messageWithDictionary:dict]; 38 | [socket send:msg]; 39 | ``` 40 | 41 | **Note:** Do **NOT** use the same socket object to connect to remote hosts and listen for incoming connections. It will not work. 42 | 43 | ## Requirements 44 | - iOS 6.0 or later 45 | - OS X 10.8 or later 46 | 47 | ## Todo 48 | - Wrap CocoaAsynSocket's **SSL support** into an easy to use API. 49 | 50 | ## Changelog 51 | 52 | **0.0.1** (Oct 16th, 2013) 53 | - First public release. 54 | 55 | ##License 56 | 57 | > PKJSONSocket - Copyright (C) 2013 Philip Kluz (Philip.Kluz@zuui.org) 58 | > 59 | > Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 60 | > 61 | > The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 62 | > 63 | > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 64 | 65 | --------------------------------------------------------------------------------