├── .gitignore ├── .travis.yml ├── CocoaAsyncSocket.podspec ├── CocoaAsyncSocket.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ └── contents.xcworkspacedata └── xcshareddata │ └── xcschemes │ ├── Mac Framework.xcscheme │ ├── iOS Framework.xcscheme │ └── tvOS Framework.xcscheme ├── Examples ├── GCD │ ├── BonjourClient │ │ ├── BonjourClient-Info.plist │ │ ├── BonjourClient.xcodeproj │ │ │ ├── project.pbxproj │ │ │ └── project.xcworkspace │ │ │ │ └── contents.xcworkspacedata │ │ ├── BonjourClientAppDelegate.h │ │ ├── BonjourClientAppDelegate.m │ │ ├── BonjourClient_Prefix.pch │ │ ├── English.lproj │ │ │ ├── InfoPlist.strings │ │ │ └── MainMenu.xib │ │ └── main.m │ ├── BonjourServer │ │ ├── BonjourServer-Info.plist │ │ ├── BonjourServer.xcodeproj │ │ │ ├── project.pbxproj │ │ │ └── project.xcworkspace │ │ │ │ └── contents.xcworkspacedata │ │ ├── BonjourServerAppDelegate.h │ │ ├── BonjourServerAppDelegate.m │ │ ├── BonjourServer_Prefix.pch │ │ ├── English.lproj │ │ │ ├── InfoPlist.strings │ │ │ └── MainMenu.xib │ │ └── main.m │ ├── ConnectTest │ │ ├── Desktop │ │ │ ├── ConnectTest.xcodeproj │ │ │ │ ├── project.pbxproj │ │ │ │ └── project.xcworkspace │ │ │ │ │ └── contents.xcworkspacedata │ │ │ └── ConnectTest │ │ │ │ ├── ConnectTest-Info.plist │ │ │ │ ├── ConnectTest-Prefix.pch │ │ │ │ ├── ConnectTestAppDelegate.h │ │ │ │ ├── ConnectTestAppDelegate.m │ │ │ │ ├── en.lproj │ │ │ │ ├── Credits.rtf │ │ │ │ ├── InfoPlist.strings │ │ │ │ └── MainMenu.xib │ │ │ │ └── main.m │ │ ├── Mobile │ │ │ ├── ConnectTest.xcodeproj │ │ │ │ ├── project.pbxproj │ │ │ │ └── project.xcworkspace │ │ │ │ │ └── contents.xcworkspacedata │ │ │ ├── ConnectTest │ │ │ │ ├── ConnectTest-Info.plist │ │ │ │ ├── ConnectTest-Prefix.pch │ │ │ │ ├── ConnectTestAppDelegate.h │ │ │ │ ├── ConnectTestAppDelegate.m │ │ │ │ ├── ConnectTestViewController.h │ │ │ │ ├── ConnectTestViewController.m │ │ │ │ ├── en.lproj │ │ │ │ │ ├── ConnectTestViewController.xib │ │ │ │ │ ├── InfoPlist.strings │ │ │ │ │ └── MainWindow.xib │ │ │ │ └── main.m │ │ │ └── Default-568h@2x.png │ │ └── ReadMe.txt │ ├── DomainTest │ │ ├── DomainTest.xcodeproj │ │ │ ├── project.pbxproj │ │ │ └── project.xcworkspace │ │ │ │ └── contents.xcworkspacedata │ │ └── DomainTest │ │ │ ├── AppDelegate.h │ │ │ ├── AppDelegate.m │ │ │ ├── DomainClient.h │ │ │ ├── DomainClient.m │ │ │ ├── DomainClient.xib │ │ │ ├── DomainServer.h │ │ │ ├── DomainServer.m │ │ │ ├── DomainTest-Info.plist │ │ │ ├── DomainTest-Prefix.pch │ │ │ ├── en.lproj │ │ │ ├── Credits.rtf │ │ │ ├── InfoPlist.strings │ │ │ └── MainMenu.xib │ │ │ └── main.m │ ├── EchoServer │ │ ├── EchoServer-Info.plist │ │ ├── EchoServer.xcodeproj │ │ │ ├── project.pbxproj │ │ │ └── project.xcworkspace │ │ │ │ └── contents.xcworkspacedata │ │ ├── EchoServerAppDelegate.h │ │ ├── EchoServerAppDelegate.m │ │ ├── EchoServer_Prefix.pch │ │ ├── English.lproj │ │ │ ├── InfoPlist.strings │ │ │ └── MainMenu.xib │ │ └── main.m │ ├── SimpleHTTPClient │ │ ├── Desktop │ │ │ ├── SimpleHTTPClient.xcodeproj │ │ │ │ ├── project.pbxproj │ │ │ │ └── project.xcworkspace │ │ │ │ │ └── contents.xcworkspacedata │ │ │ └── SimpleHTTPClient │ │ │ │ ├── SimpleHTTPClient-Info.plist │ │ │ │ ├── SimpleHTTPClient-Prefix.pch │ │ │ │ ├── SimpleHTTPClientAppDelegate.h │ │ │ │ ├── SimpleHTTPClientAppDelegate.m │ │ │ │ ├── en.lproj │ │ │ │ ├── Credits.rtf │ │ │ │ ├── InfoPlist.strings │ │ │ │ └── MainMenu.xib │ │ │ │ └── main.m │ │ ├── Mobile │ │ │ ├── Default-568h@2x.png │ │ │ ├── SimpleHTTPClient.xcodeproj │ │ │ │ ├── project.pbxproj │ │ │ │ └── project.xcworkspace │ │ │ │ │ └── contents.xcworkspacedata │ │ │ └── SimpleHTTPClient │ │ │ │ ├── SimpleHTTPClient-Info.plist │ │ │ │ ├── SimpleHTTPClient-Prefix.pch │ │ │ │ ├── SimpleHTTPClientAppDelegate.h │ │ │ │ ├── SimpleHTTPClientAppDelegate.m │ │ │ │ ├── SimpleHTTPClientViewController.h │ │ │ │ ├── SimpleHTTPClientViewController.m │ │ │ │ ├── en.lproj │ │ │ │ ├── InfoPlist.strings │ │ │ │ ├── MainWindow.xib │ │ │ │ └── SimpleHTTPClientViewController.xib │ │ │ │ └── main.m │ │ └── ReadMe.txt │ ├── TestPreBuffer │ │ ├── Desktop │ │ │ ├── TestPreBuffer.xcodeproj │ │ │ │ ├── project.pbxproj │ │ │ │ └── project.xcworkspace │ │ │ │ │ └── contents.xcworkspacedata │ │ │ └── TestPreBuffer │ │ │ │ ├── AppDelegate.h │ │ │ │ ├── AppDelegate.m │ │ │ │ ├── TestPreBuffer-Info.plist │ │ │ │ ├── TestPreBuffer-Prefix.pch │ │ │ │ ├── en.lproj │ │ │ │ ├── Credits.rtf │ │ │ │ ├── InfoPlist.strings │ │ │ │ └── MainMenu.xib │ │ │ │ └── main.m │ │ ├── Mobile │ │ │ ├── Default-568h@2x.png │ │ │ ├── TestPreBuffer.xcodeproj │ │ │ │ ├── project.pbxproj │ │ │ │ └── project.xcworkspace │ │ │ │ │ └── contents.xcworkspacedata │ │ │ └── TestPreBuffer │ │ │ │ ├── AppDelegate.h │ │ │ │ ├── AppDelegate.m │ │ │ │ ├── TestPreBuffer-Info.plist │ │ │ │ ├── TestPreBuffer-Prefix.pch │ │ │ │ ├── ViewController.h │ │ │ │ ├── ViewController.m │ │ │ │ ├── en.lproj │ │ │ │ ├── InfoPlist.strings │ │ │ │ ├── ViewController_iPad.xib │ │ │ │ └── ViewController_iPhone.xib │ │ │ │ └── main.m │ │ └── Shared │ │ │ ├── TestPreBuffer.h │ │ │ └── TestPreBuffer.m │ ├── UdpEchoClient │ │ ├── Desktop │ │ │ ├── UdpEchoClient.xcodeproj │ │ │ │ ├── project.pbxproj │ │ │ │ └── project.xcworkspace │ │ │ │ │ └── contents.xcworkspacedata │ │ │ └── UdpEchoClient │ │ │ │ ├── AppDelegate.h │ │ │ │ ├── AppDelegate.m │ │ │ │ ├── UdpEchoClient-Info.plist │ │ │ │ ├── UdpEchoClient-Prefix.pch │ │ │ │ ├── en.lproj │ │ │ │ ├── Credits.rtf │ │ │ │ ├── InfoPlist.strings │ │ │ │ └── MainMenu.xib │ │ │ │ └── main.m │ │ └── Mobile │ │ │ ├── Default-568h@2x.png │ │ │ ├── UdpEchoClient.xcodeproj │ │ │ ├── project.pbxproj │ │ │ └── project.xcworkspace │ │ │ │ └── contents.xcworkspacedata │ │ │ └── UdpEchoClient │ │ │ ├── AppDelegate.h │ │ │ ├── AppDelegate.m │ │ │ ├── UdpEchoClient-Info.plist │ │ │ ├── UdpEchoClient-Prefix.pch │ │ │ ├── ViewController.h │ │ │ ├── ViewController.m │ │ │ ├── en.lproj │ │ │ ├── InfoPlist.strings │ │ │ └── ViewController.xib │ │ │ └── main.m │ └── UdpEchoServer │ │ ├── Desktop │ │ ├── UdpEchoServer.xcodeproj │ │ │ ├── project.pbxproj │ │ │ └── project.xcworkspace │ │ │ │ └── contents.xcworkspacedata │ │ └── UdpEchoServer │ │ │ ├── AppDelegate.h │ │ │ ├── AppDelegate.m │ │ │ ├── UdpEchoServer-Info.plist │ │ │ ├── UdpEchoServer-Prefix.pch │ │ │ ├── en.lproj │ │ │ ├── Credits.rtf │ │ │ ├── InfoPlist.strings │ │ │ └── MainMenu.xib │ │ │ └── main.m │ │ └── Mobile │ │ ├── UdpEchoServer.xcodeproj │ │ ├── project.pbxproj │ │ └── project.xcworkspace │ │ │ └── contents.xcworkspacedata │ │ └── UdpEchoServer │ │ ├── AppDelegate.h │ │ ├── AppDelegate.m │ │ ├── UdpEchoServer-Info.plist │ │ ├── UdpEchoServer-Prefix.pch │ │ ├── ViewController.h │ │ ├── ViewController.m │ │ ├── en.lproj │ │ ├── InfoPlist.strings │ │ └── ViewController.xib │ │ └── main.m └── RunLoop │ ├── EchoServer │ ├── AppController.h │ ├── AppController.m │ ├── EchoServer.xcodeproj │ │ ├── project.pbxproj │ │ └── project.xcworkspace │ │ │ └── contents.xcworkspacedata │ ├── EchoServer_Prefix.pch │ ├── English.lproj │ │ ├── InfoPlist.strings │ │ └── MainMenu.nib │ │ │ ├── designable.nib │ │ │ └── keyedobjects.nib │ ├── Info.plist │ ├── Instructions.txt │ └── main.m │ ├── InterfaceTest │ ├── Classes │ │ ├── InterfaceTestAppDelegate.h │ │ ├── InterfaceTestAppDelegate.m │ │ ├── InterfaceTestViewController.h │ │ └── InterfaceTestViewController.m │ ├── Default-568h@2x.png │ ├── InterfaceTest-Info.plist │ ├── InterfaceTest.xcodeproj │ │ ├── project.pbxproj │ │ └── project.xcworkspace │ │ │ └── contents.xcworkspacedata │ ├── InterfaceTestViewController.xib │ ├── InterfaceTest_Prefix.pch │ ├── MainWindow.xib │ ├── Readme.txt │ └── main.m │ ├── UdpEchoClient │ ├── UdpEchoClient.xcodeproj │ │ ├── project.pbxproj │ │ └── project.xcworkspace │ │ │ └── contents.xcworkspacedata │ └── UdpEchoClient │ │ ├── AppDelegate.h │ │ ├── AppDelegate.m │ │ ├── UdpEchoClient-Info.plist │ │ ├── UdpEchoClient-Prefix.pch │ │ ├── en.lproj │ │ ├── Credits.rtf │ │ ├── InfoPlist.strings │ │ └── MainMenu.xib │ │ └── main.m │ └── UdpEchoServer │ ├── UdpEchoServer.xcodeproj │ ├── project.pbxproj │ └── project.xcworkspace │ │ └── contents.xcworkspacedata │ └── UdpEchoServer │ ├── AppDelegate.h │ ├── AppDelegate.m │ ├── UdpEchoServer-Info.plist │ ├── UdpEchoServer-Prefix.pch │ ├── en.lproj │ ├── Credits.rtf │ ├── InfoPlist.strings │ └── MainMenu.xib │ └── main.m ├── README.markdown ├── Source ├── CocoaAsyncSocket.h ├── GCD │ ├── Documentation.html │ ├── GCDAsyncSocket.h │ ├── GCDAsyncSocket.m │ ├── GCDAsyncUdpSocket.h │ └── GCDAsyncUdpSocket.m ├── Info.plist ├── RunLoop │ ├── AsyncSocket.h │ ├── AsyncSocket.m │ ├── AsyncUdpSocket.h │ ├── AsyncUdpSocket.m │ └── Documentation.html └── Vendor │ └── CocoaLumberjack │ ├── DDASLLogger.h │ ├── DDASLLogger.m │ ├── DDAbstractDatabaseLogger.h │ ├── DDAbstractDatabaseLogger.m │ ├── DDFileLogger.h │ ├── DDFileLogger.m │ ├── DDLog+LOGV.h │ ├── DDLog.h │ ├── DDLog.m │ ├── DDTTYLogger.h │ ├── DDTTYLogger.m │ └── Extensions │ ├── DDContextFilterLogFormatter.h │ ├── DDContextFilterLogFormatter.m │ ├── DDDispatchQueueLogFormatter.h │ ├── DDDispatchQueueLogFormatter.m │ ├── DDMultiFormatter.h │ ├── DDMultiFormatter.m │ └── README.txt └── Tests ├── Mac ├── CocoaAsyncSocket.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ └── contents.xcworkspacedata │ └── xcshareddata │ │ └── xcschemes │ │ └── CocoaAsyncSocketTestsMac.xcscheme ├── CocoaAsyncSocket.xcworkspace │ └── contents.xcworkspacedata ├── GCDAsyncSocketUNTests.m ├── Info.plist ├── Podfile └── Podfile.lock ├── Shared ├── GCDAsyncSocketConnectionTests.m └── SwiftTests.swift └── iOS ├── CocoaAsyncSocket.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ └── contents.xcworkspacedata └── xcshareddata │ └── xcschemes │ └── CocoaAsyncSocketTestsiOS.xcscheme ├── CocoaAsyncSocket.xcworkspace └── contents.xcworkspacedata ├── Info.plist ├── Podfile └── Podfile.lock /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## Build generated 6 | build/ 7 | DerivedData 8 | 9 | ## Various settings 10 | *.pbxuser 11 | !default.pbxuser 12 | *.mode1v3 13 | !default.mode1v3 14 | *.mode2v3 15 | !default.mode2v3 16 | *.perspectivev3 17 | !default.perspectivev3 18 | xcuserdata 19 | 20 | ## Other 21 | .DS_Store 22 | *.xccheckout 23 | *.moved-aside 24 | *.xcuserstate 25 | *.xcscmblueprint 26 | 27 | ## Obj-C/Swift specific 28 | *.hmap 29 | *.ipa 30 | 31 | # CocoaPods 32 | # 33 | # We recommend against adding the Pods directory to your .gitignore. However 34 | # you should judge for yourself, the pros and cons are mentioned at: 35 | # http://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 36 | # 37 | Pods/ 38 | 39 | # Carthage 40 | # 41 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 42 | # Carthage/Checkouts 43 | 44 | Carthage/Build -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: objective-c 2 | osx_image: xcode7.2 3 | 4 | install: 5 | - pod install --project-directory=./Tests/iOS --no-repo-update 6 | - pod install --project-directory=./Tests/Mac --no-repo-update 7 | 8 | script: 9 | - xctool -workspace ./Tests/iOS/CocoaAsyncSocket.xcworkspace -scheme CocoaAsyncSocketTestsiOS -sdk iphonesimulator -arch i386 test 10 | - xctool -workspace ./Tests/Mac/CocoaAsyncSocket.xcworkspace -scheme CocoaAsyncSocketTestsMac -sdk macosx -arch x86_64 test 11 | - xctool -project CocoaAsyncSocket.xcodeproj -scheme "iOS Framework" -sdk iphonesimulator -arch i386 build 12 | - xctool -project CocoaAsyncSocket.xcodeproj -scheme "Mac Framework" -sdk macosx -arch x86_64 build -------------------------------------------------------------------------------- /CocoaAsyncSocket.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | s.name = 'CocoaAsyncSocket' 3 | s.version = '7.4.3' 4 | s.license = { :type => 'public domain', :text => <<-LICENSE 5 | Public Domain License 6 | 7 | The CocoaAsyncSocket project is in the public domain. 8 | 9 | The original TCP version (AsyncSocket) was created by Dustin Voss in January 2003. 10 | Updated and maintained by Deusty LLC and the Apple development community. 11 | LICENSE 12 | } 13 | s.summary = 'Asynchronous socket networking library for Mac and iOS.' 14 | s.homepage = 'https://github.com/robbiehanson/CocoaAsyncSocket' 15 | s.authors = 'Dustin Voss', { 'Robbie Hanson' => 'robbiehanson@deusty.com' } 16 | 17 | s.source = { :git => 'https://github.com/robbiehanson/CocoaAsyncSocket.git', 18 | :tag => "#{s.version}" } 19 | 20 | s.description = 'CocoaAsyncSocket supports TCP and UDP. The AsyncSocket class is for TCP, and the AsyncUdpSocket class is for UDP. ' \ 21 | 'AsyncSocket is a TCP/IP socket networking library that wraps CFSocket and CFStream. It offers asynchronous ' \ 22 | 'operation, and a native Cocoa class complete with delegate support or use the GCD variant GCDAsyncSocket. ' \ 23 | 'AsyncUdpSocket is a UDP/IP socket networking library that wraps CFSocket. It works almost exactly like the TCP ' \ 24 | 'version, but is designed specifically for UDP. This includes queued non-blocking send/receive operations, full ' \ 25 | 'delegate support, run-loop based, self-contained class, and support for IPv4 and IPv6.' 26 | 27 | s.default_subspec = 'All' 28 | 29 | s.subspec 'All' do |ss| 30 | ss.dependency 'CocoaAsyncSocket/GCD' 31 | ss.dependency 'CocoaAsyncSocket/RunLoop' 32 | end 33 | 34 | s.subspec 'GCD' do |ss| 35 | ss.source_files = 'Source/GCD/*.{h,m}' 36 | end 37 | 38 | s.subspec 'RunLoop' do |ss| 39 | ss.source_files = 'Source/RunLoop/*.{h,m}' 40 | end 41 | 42 | s.requires_arc = true 43 | 44 | # dispatch_queue_set_specific() is available in OS X v10.7+ and iOS 5.0+ 45 | s.ios.deployment_target = '5.0' 46 | s.tvos.deployment_target = '9.0' 47 | s.osx.deployment_target = '10.7' 48 | 49 | s.ios.frameworks = 'CFNetwork', 'Security' 50 | s.tvos.frameworks = 'CFNetwork', 'Security' 51 | s.osx.frameworks = 'CoreServices', 'Security' 52 | end 53 | -------------------------------------------------------------------------------- /CocoaAsyncSocket.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /CocoaAsyncSocket.xcodeproj/xcshareddata/xcschemes/Mac Framework.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 29 | 35 | 36 | 37 | 38 | 39 | 44 | 45 | 47 | 53 | 54 | 55 | 56 | 57 | 63 | 64 | 65 | 66 | 75 | 76 | 82 | 83 | 84 | 85 | 86 | 87 | 93 | 94 | 100 | 101 | 102 | 103 | 105 | 106 | 109 | 110 | 111 | -------------------------------------------------------------------------------- /CocoaAsyncSocket.xcodeproj/xcshareddata/xcschemes/iOS Framework.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 33 | 39 | 40 | 41 | 42 | 43 | 49 | 50 | 51 | 52 | 53 | 54 | 64 | 65 | 71 | 72 | 73 | 74 | 75 | 76 | 82 | 83 | 89 | 90 | 91 | 92 | 94 | 95 | 98 | 99 | 100 | -------------------------------------------------------------------------------- /CocoaAsyncSocket.xcodeproj/xcshareddata/xcschemes/tvOS Framework.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 34 | 35 | 45 | 46 | 52 | 53 | 54 | 55 | 56 | 57 | 63 | 64 | 70 | 71 | 72 | 73 | 75 | 76 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /Examples/GCD/BonjourClient/BonjourClient-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIconFile 10 | 11 | CFBundleIdentifier 12 | com.yourcompany.${PRODUCT_NAME:rfc1034identifier} 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1 25 | LSMinimumSystemVersion 26 | ${MACOSX_DEPLOYMENT_TARGET} 27 | NSMainNibFile 28 | MainMenu 29 | NSPrincipalClass 30 | NSApplication 31 | 32 | 33 | -------------------------------------------------------------------------------- /Examples/GCD/BonjourClient/BonjourClient.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Examples/GCD/BonjourClient/BonjourClientAppDelegate.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | @class GCDAsyncSocket; 4 | 5 | 6 | @interface BonjourClientAppDelegate : NSObject 7 | { 8 | NSNetServiceBrowser *netServiceBrowser; 9 | NSNetService *serverService; 10 | NSMutableArray *serverAddresses; 11 | GCDAsyncSocket *asyncSocket; 12 | BOOL connected; 13 | 14 | NSWindow *__unsafe_unretained window; 15 | } 16 | 17 | @property (unsafe_unretained) IBOutlet NSWindow *window; 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /Examples/GCD/BonjourClient/BonjourClientAppDelegate.m: -------------------------------------------------------------------------------- 1 | #import "BonjourClientAppDelegate.h" 2 | #import "GCDAsyncSocket.h" 3 | #import "DDLog.h" 4 | #import "DDTTYLogger.h" 5 | #import "DDASLLogger.h" 6 | 7 | // Log levels: off, error, warn, info, verbose 8 | static const int ddLogLevel = LOG_LEVEL_VERBOSE; 9 | 10 | @interface BonjourClientAppDelegate (Private) 11 | - (void)connectToNextAddress; 12 | @end 13 | 14 | #pragma mark - 15 | 16 | @implementation BonjourClientAppDelegate 17 | 18 | @synthesize window; 19 | 20 | - (void)applicationDidFinishLaunching:(NSNotification *)aNotification 21 | { 22 | // Configure logging framework 23 | 24 | [DDLog addLogger:[DDTTYLogger sharedInstance]]; 25 | [DDLog addLogger:[DDASLLogger sharedInstance]]; 26 | 27 | // Start browsing for bonjour services 28 | 29 | netServiceBrowser = [[NSNetServiceBrowser alloc] init]; 30 | 31 | [netServiceBrowser setDelegate:self]; 32 | [netServiceBrowser searchForServicesOfType:@"_YourServiceName._tcp." inDomain:@"local."]; 33 | } 34 | 35 | - (void)netServiceBrowser:(NSNetServiceBrowser *)sender didNotSearch:(NSDictionary *)errorInfo 36 | { 37 | DDLogError(@"DidNotSearch: %@", errorInfo); 38 | } 39 | 40 | - (void)netServiceBrowser:(NSNetServiceBrowser *)sender 41 | didFindService:(NSNetService *)netService 42 | moreComing:(BOOL)moreServicesComing 43 | { 44 | DDLogVerbose(@"DidFindService: %@", [netService name]); 45 | 46 | // Connect to the first service we find 47 | 48 | if (serverService == nil) 49 | { 50 | DDLogVerbose(@"Resolving..."); 51 | 52 | serverService = netService; 53 | 54 | [serverService setDelegate:self]; 55 | [serverService resolveWithTimeout:5.0]; 56 | } 57 | } 58 | 59 | - (void)netServiceBrowser:(NSNetServiceBrowser *)sender 60 | didRemoveService:(NSNetService *)netService 61 | moreComing:(BOOL)moreServicesComing 62 | { 63 | DDLogVerbose(@"DidRemoveService: %@", [netService name]); 64 | } 65 | 66 | - (void)netServiceBrowserDidStopSearch:(NSNetServiceBrowser *)sender 67 | { 68 | DDLogInfo(@"DidStopSearch"); 69 | } 70 | 71 | - (void)netService:(NSNetService *)sender didNotResolve:(NSDictionary *)errorDict 72 | { 73 | DDLogError(@"DidNotResolve"); 74 | } 75 | 76 | - (void)netServiceDidResolveAddress:(NSNetService *)sender 77 | { 78 | DDLogInfo(@"DidResolve: %@", [sender addresses]); 79 | 80 | if (serverAddresses == nil) 81 | { 82 | serverAddresses = [[sender addresses] mutableCopy]; 83 | } 84 | 85 | if (asyncSocket == nil) 86 | { 87 | asyncSocket = [[GCDAsyncSocket alloc] initWithDelegate:self delegateQueue:dispatch_get_main_queue()]; 88 | 89 | [self connectToNextAddress]; 90 | } 91 | } 92 | 93 | - (void)connectToNextAddress 94 | { 95 | BOOL done = NO; 96 | 97 | while (!done && ([serverAddresses count] > 0)) 98 | { 99 | NSData *addr; 100 | 101 | // Note: The serverAddresses array probably contains both IPv4 and IPv6 addresses. 102 | // 103 | // If your server is also using GCDAsyncSocket then you don't have to worry about it, 104 | // as the socket automatically handles both protocols for you transparently. 105 | 106 | if (YES) // Iterate forwards 107 | { 108 | addr = [serverAddresses objectAtIndex:0]; 109 | [serverAddresses removeObjectAtIndex:0]; 110 | } 111 | else // Iterate backwards 112 | { 113 | addr = [serverAddresses lastObject]; 114 | [serverAddresses removeLastObject]; 115 | } 116 | 117 | DDLogVerbose(@"Attempting connection to %@", addr); 118 | 119 | NSError *err = nil; 120 | if ([asyncSocket connectToAddress:addr error:&err]) 121 | { 122 | done = YES; 123 | } 124 | else 125 | { 126 | DDLogWarn(@"Unable to connect: %@", err); 127 | } 128 | 129 | } 130 | 131 | if (!done) 132 | { 133 | DDLogWarn(@"Unable to connect to any resolved address"); 134 | } 135 | } 136 | 137 | - (void)socket:(GCDAsyncSocket *)sock didConnectToHost:(NSString *)host port:(UInt16)port 138 | { 139 | DDLogInfo(@"Socket:DidConnectToHost: %@ Port: %hu", host, port); 140 | 141 | connected = YES; 142 | } 143 | 144 | - (void)socketDidDisconnect:(GCDAsyncSocket *)sock withError:(NSError *)err 145 | { 146 | DDLogWarn(@"SocketDidDisconnect:WithError: %@", err); 147 | 148 | if (!connected) 149 | { 150 | [self connectToNextAddress]; 151 | } 152 | } 153 | 154 | @end 155 | -------------------------------------------------------------------------------- /Examples/GCD/BonjourClient/BonjourClient_Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'BonjourClient' target in the 'BonjourClient' project 3 | // 4 | 5 | #ifdef __OBJC__ 6 | #import 7 | #endif 8 | -------------------------------------------------------------------------------- /Examples/GCD/BonjourClient/English.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /Examples/GCD/BonjourClient/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // BonjourClient 4 | // 5 | // Created by Robbie Hanson on 1/27/11. 6 | // Copyright 2011 Voalte. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | int main(int argc, char *argv[]) 12 | { 13 | return NSApplicationMain(argc, (const char **) argv); 14 | } 15 | -------------------------------------------------------------------------------- /Examples/GCD/BonjourServer/BonjourServer-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIconFile 10 | 11 | CFBundleIdentifier 12 | com.yourcompany.${PRODUCT_NAME:rfc1034identifier} 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1 25 | LSMinimumSystemVersion 26 | ${MACOSX_DEPLOYMENT_TARGET} 27 | NSMainNibFile 28 | MainMenu 29 | NSPrincipalClass 30 | NSApplication 31 | 32 | 33 | -------------------------------------------------------------------------------- /Examples/GCD/BonjourServer/BonjourServer.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Examples/GCD/BonjourServer/BonjourServerAppDelegate.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | @class GCDAsyncSocket; 4 | 5 | 6 | @interface BonjourServerAppDelegate : NSObject 7 | { 8 | NSNetService *netService; 9 | GCDAsyncSocket *asyncSocket; 10 | NSMutableArray *connectedSockets; 11 | 12 | NSWindow *__unsafe_unretained window; 13 | } 14 | 15 | @property (unsafe_unretained) IBOutlet NSWindow *window; 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /Examples/GCD/BonjourServer/BonjourServerAppDelegate.m: -------------------------------------------------------------------------------- 1 | #import "BonjourServerAppDelegate.h" 2 | #import "GCDAsyncSocket.h" 3 | #import "DDLog.h" 4 | #import "DDTTYLogger.h" 5 | #import "DDASLLogger.h" 6 | 7 | // Log levels: off, error, warn, info, verbose 8 | static const int ddLogLevel = LOG_LEVEL_VERBOSE; 9 | 10 | 11 | @implementation BonjourServerAppDelegate 12 | 13 | @synthesize window; 14 | 15 | - (void)applicationDidFinishLaunching:(NSNotification *)aNotification 16 | { 17 | // Configure logging framework 18 | 19 | [DDLog addLogger:[DDTTYLogger sharedInstance]]; 20 | [DDLog addLogger:[DDASLLogger sharedInstance]]; 21 | 22 | // Create our socket. 23 | // We tell it to invoke our delegate methods on the main thread. 24 | 25 | asyncSocket = [[GCDAsyncSocket alloc] initWithDelegate:self delegateQueue:dispatch_get_main_queue()]; 26 | 27 | // Create an array to hold accepted incoming connections. 28 | 29 | connectedSockets = [[NSMutableArray alloc] init]; 30 | 31 | // Now we tell the socket to accept incoming connections. 32 | // We don't care what port it listens on, so we pass zero for the port number. 33 | // This allows the operating system to automatically assign us an available port. 34 | 35 | NSError *err = nil; 36 | if ([asyncSocket acceptOnPort:0 error:&err]) 37 | { 38 | // So what port did the OS give us? 39 | 40 | UInt16 port = [asyncSocket localPort]; 41 | 42 | // Create and publish the bonjour service. 43 | // Obviously you will be using your own custom service type. 44 | 45 | netService = [[NSNetService alloc] initWithDomain:@"local." 46 | type:@"_YourServiceName._tcp." 47 | name:@"" 48 | port:port]; 49 | 50 | [netService setDelegate:self]; 51 | [netService publish]; 52 | 53 | // You can optionally add TXT record stuff 54 | 55 | NSMutableDictionary *txtDict = [NSMutableDictionary dictionaryWithCapacity:2]; 56 | 57 | [txtDict setObject:@"moo" forKey:@"cow"]; 58 | [txtDict setObject:@"quack" forKey:@"duck"]; 59 | 60 | NSData *txtData = [NSNetService dataFromTXTRecordDictionary:txtDict]; 61 | [netService setTXTRecordData:txtData]; 62 | } 63 | else 64 | { 65 | DDLogError(@"Error in acceptOnPort:error: -> %@", err); 66 | } 67 | } 68 | 69 | - (void)socket:(GCDAsyncSocket *)sock didAcceptNewSocket:(GCDAsyncSocket *)newSocket 70 | { 71 | DDLogInfo(@"Accepted new socket from %@:%hu", [newSocket connectedHost], [newSocket connectedPort]); 72 | 73 | // The newSocket automatically inherits its delegate & delegateQueue from its parent. 74 | 75 | [connectedSockets addObject:newSocket]; 76 | } 77 | 78 | - (void)socketDidDisconnect:(GCDAsyncSocket *)sock withError:(NSError *)err 79 | { 80 | [connectedSockets removeObject:sock]; 81 | } 82 | 83 | - (void)netServiceDidPublish:(NSNetService *)ns 84 | { 85 | DDLogInfo(@"Bonjour Service Published: domain(%@) type(%@) name(%@) port(%i)", 86 | [ns domain], [ns type], [ns name], (int)[ns port]); 87 | } 88 | 89 | - (void)netService:(NSNetService *)ns didNotPublish:(NSDictionary *)errorDict 90 | { 91 | // Override me to do something here... 92 | // 93 | // Note: This method in invoked on our bonjour thread. 94 | 95 | DDLogError(@"Failed to Publish Service: domain(%@) type(%@) name(%@) - %@", 96 | [ns domain], [ns type], [ns name], errorDict); 97 | } 98 | 99 | @end 100 | -------------------------------------------------------------------------------- /Examples/GCD/BonjourServer/BonjourServer_Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'BonjourServer' target in the 'BonjourServer' project 3 | // 4 | 5 | #ifdef __OBJC__ 6 | #import 7 | #endif 8 | -------------------------------------------------------------------------------- /Examples/GCD/BonjourServer/English.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /Examples/GCD/BonjourServer/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // BonjourServer 4 | // 5 | // Created by Robbie Hanson on 1/27/11. 6 | // Copyright 2011 Voalte. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | int main(int argc, char *argv[]) 12 | { 13 | return NSApplicationMain(argc, (const char **) argv); 14 | } 15 | -------------------------------------------------------------------------------- /Examples/GCD/ConnectTest/Desktop/ConnectTest.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Examples/GCD/ConnectTest/Desktop/ConnectTest/ConnectTest-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIconFile 10 | 11 | CFBundleIdentifier 12 | com.deusty.oss.${PRODUCT_NAME:rfc1034identifier} 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1 25 | LSMinimumSystemVersion 26 | ${MACOSX_DEPLOYMENT_TARGET} 27 | NSMainNibFile 28 | MainMenu 29 | NSPrincipalClass 30 | NSApplication 31 | 32 | 33 | -------------------------------------------------------------------------------- /Examples/GCD/ConnectTest/Desktop/ConnectTest/ConnectTest-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'ConnectTest' target in the 'ConnectTest' project 3 | // 4 | 5 | #ifdef __OBJC__ 6 | #import 7 | #endif 8 | -------------------------------------------------------------------------------- /Examples/GCD/ConnectTest/Desktop/ConnectTest/ConnectTestAppDelegate.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | @class GCDAsyncSocket; 4 | 5 | 6 | @interface ConnectTestAppDelegate : NSObject { 7 | @private 8 | GCDAsyncSocket *asyncSocket; 9 | 10 | NSWindow *__unsafe_unretained window; 11 | } 12 | 13 | @property (unsafe_unretained) IBOutlet NSWindow *window; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /Examples/GCD/ConnectTest/Desktop/ConnectTest/ConnectTestAppDelegate.m: -------------------------------------------------------------------------------- 1 | #import "ConnectTestAppDelegate.h" 2 | #import "GCDAsyncSocket.h" 3 | #import "DDLog.h" 4 | #import "DDTTYLogger.h" 5 | 6 | // Log levels: off, error, warn, info, verbose 7 | static const int ddLogLevel = LOG_LEVEL_INFO; 8 | 9 | #define USE_SECURE_CONNECTION 0 10 | 11 | 12 | @implementation ConnectTestAppDelegate 13 | 14 | @synthesize window; 15 | 16 | - (void)applicationDidFinishLaunching:(NSNotification *)aNotification 17 | { 18 | // Setup logging framework 19 | [DDLog addLogger:[DDTTYLogger sharedInstance]]; 20 | 21 | DDLogInfo(@"%@", THIS_METHOD); 22 | 23 | // Setup our socket (GCDAsyncSocket). 24 | // The socket will invoke our delegate methods using the usual delegate paradigm. 25 | // However, it will invoke the delegate methods on a specified GCD delegate dispatch queue. 26 | // 27 | // Now we can configure the delegate dispatch queue however we want. 28 | // We could use a dedicated dispatch queue for easy parallelization. 29 | // Or we could simply use the dispatch queue for the main thread. 30 | // 31 | // The best approach for your application will depend upon convenience, requirements and performance. 32 | // 33 | // For this simple example, we're just going to use the main thread. 34 | 35 | dispatch_queue_t mainQueue = dispatch_get_main_queue(); 36 | 37 | asyncSocket = [[GCDAsyncSocket alloc] initWithDelegate:self delegateQueue:mainQueue]; 38 | 39 | #if USE_SECURE_CONNECTION 40 | { 41 | NSString *host = @"www.paypal.com"; 42 | uint16_t port = 443; 43 | 44 | DDLogInfo(@"Connecting to \"%@\" on port %hu...", host, port); 45 | 46 | NSError *error = nil; 47 | if (![asyncSocket connectToHost:@"www.paypal.com" onPort:port error:&error]) 48 | { 49 | DDLogError(@"Error connecting: %@", error); 50 | } 51 | } 52 | #else 53 | { 54 | NSString *host = @"google.com"; 55 | uint16_t port = 80; 56 | 57 | 58 | DDLogInfo(@"Connecting to \"%@\" on port %hu...", host, port); 59 | 60 | NSError *error = nil; 61 | if (![asyncSocket connectToHost:host onPort:port error:&error]) 62 | { 63 | DDLogError(@"Error connecting: %@", error); 64 | } 65 | 66 | // You can also specify an optional connect timeout. 67 | 68 | // NSError *error = nil; 69 | // if (![asyncSocket connectToHost:host onPort:80 withTimeout:5.0 error:&error]) 70 | // { 71 | // DDLogError(@"Error connecting: %@", error); 72 | // } 73 | 74 | } 75 | #endif 76 | } 77 | 78 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 79 | #pragma mark Socket Delegate 80 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 81 | 82 | - (void)socket:(GCDAsyncSocket *)sock didConnectToHost:(NSString *)host port:(UInt16)port 83 | { 84 | DDLogInfo(@"socket:%p didConnectToHost:%@ port:%hu", sock, host, port); 85 | 86 | // DDLogInfo(@"localHost :%@ port:%hu", [sock localHost], [sock localPort]); 87 | 88 | #if USE_SECURE_CONNECTION 89 | { 90 | // Connected to secure server (HTTPS) 91 | 92 | // Configure SSL/TLS settings 93 | NSMutableDictionary *settings = [NSMutableDictionary dictionaryWithCapacity:3]; 94 | 95 | // If you simply want to ensure that the remote host's certificate is valid, 96 | // then you can use an empty dictionary. 97 | 98 | // If you know the name of the remote host, then you should specify the name here. 99 | // 100 | // NOTE: 101 | // You should understand the security implications if you do not specify the peer name. 102 | // Please see the documentation for the startTLS method in GCDAsyncSocket.h for a full discussion. 103 | 104 | [settings setObject:@"www.paypal.com" 105 | forKey:(NSString *)kCFStreamSSLPeerName]; 106 | 107 | // To connect to a test server, with a self-signed certificate, use settings similar to this: 108 | 109 | // // Allow expired certificates 110 | // [settings setObject:[NSNumber numberWithBool:YES] 111 | // forKey:(NSString *)kCFStreamSSLAllowsExpiredCertificates]; 112 | // 113 | // // Allow self-signed certificates 114 | // [settings setObject:[NSNumber numberWithBool:YES] 115 | // forKey:(NSString *)kCFStreamSSLAllowsAnyRoot]; 116 | // 117 | // // In fact, don't even validate the certificate chain 118 | // [settings setObject:[NSNumber numberWithBool:NO] 119 | // forKey:(NSString *)kCFStreamSSLValidatesCertificateChain]; 120 | 121 | DDLogInfo(@"Starting TLS with settings:\n%@", settings); 122 | 123 | [sock startTLS:settings]; 124 | 125 | // You can also pass nil to the startTLS method, which is the same as passing an empty dictionary. 126 | // Again, you should understand the security implications of doing so. 127 | // Please see the documentation for the startTLS method in GCDAsyncSocket.h for a full discussion. 128 | 129 | } 130 | #else 131 | { 132 | // Connected to normal server (HTTP) 133 | } 134 | #endif 135 | } 136 | 137 | - (void)socketDidSecure:(GCDAsyncSocket *)sock 138 | { 139 | DDLogInfo(@"socketDidSecure:%p", sock); 140 | } 141 | 142 | - (void)socket:(GCDAsyncSocket *)sock didWriteDataWithTag:(long)tag 143 | { 144 | DDLogInfo(@"socket:%p didWriteDataWithTag:%ld", sock, tag); 145 | } 146 | 147 | - (void)socket:(GCDAsyncSocket *)sock didReadData:(NSData *)data withTag:(long)tag 148 | { 149 | DDLogInfo(@"socket:%p didReadData:withTag:%ld", sock, tag); 150 | } 151 | 152 | - (void)socketDidDisconnect:(GCDAsyncSocket *)sock withError:(NSError *)err 153 | { 154 | DDLogInfo(@"socketDidDisconnect:%p withError: %@", sock, err); 155 | } 156 | 157 | @end 158 | -------------------------------------------------------------------------------- /Examples/GCD/ConnectTest/Desktop/ConnectTest/en.lproj/Credits.rtf: -------------------------------------------------------------------------------- 1 | {\rtf0\ansi{\fonttbl\f0\fswiss Helvetica;} 2 | {\colortbl;\red255\green255\blue255;} 3 | \paperw9840\paperh8400 4 | \pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural 5 | 6 | \f0\b\fs24 \cf0 Engineering: 7 | \b0 \ 8 | Some people\ 9 | \ 10 | 11 | \b Human Interface Design: 12 | \b0 \ 13 | Some other people\ 14 | \ 15 | 16 | \b Testing: 17 | \b0 \ 18 | Hopefully not nobody\ 19 | \ 20 | 21 | \b Documentation: 22 | \b0 \ 23 | Whoever\ 24 | \ 25 | 26 | \b With special thanks to: 27 | \b0 \ 28 | Mom\ 29 | } 30 | -------------------------------------------------------------------------------- /Examples/GCD/ConnectTest/Desktop/ConnectTest/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /Examples/GCD/ConnectTest/Desktop/ConnectTest/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // ConnectTest 4 | // 5 | // Created by Robbie Hanson on 7/23/11. 6 | // Copyright 2011 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | int main(int argc, char *argv[]) 12 | { 13 | return NSApplicationMain(argc, (const char **)argv); 14 | } 15 | -------------------------------------------------------------------------------- /Examples/GCD/ConnectTest/Mobile/ConnectTest.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Examples/GCD/ConnectTest/Mobile/ConnectTest/ConnectTest-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDisplayName 8 | ${PRODUCT_NAME} 9 | CFBundleExecutable 10 | ${EXECUTABLE_NAME} 11 | CFBundleIconFile 12 | 13 | CFBundleIdentifier 14 | com.deusty.oss.${PRODUCT_NAME:rfc1034identifier} 15 | CFBundleInfoDictionaryVersion 16 | 6.0 17 | CFBundleName 18 | ${PRODUCT_NAME} 19 | CFBundlePackageType 20 | APPL 21 | CFBundleShortVersionString 22 | 1.0 23 | CFBundleSignature 24 | ???? 25 | CFBundleVersion 26 | 1.0 27 | LSRequiresIPhoneOS 28 | 29 | NSMainNibFile 30 | MainWindow 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /Examples/GCD/ConnectTest/Mobile/ConnectTest/ConnectTest-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'ConnectTest' target in the 'ConnectTest' project 3 | // 4 | 5 | #import 6 | 7 | #ifndef __IPHONE_3_0 8 | #warning "This project uses features only available in iPhone SDK 3.0 and later." 9 | #endif 10 | 11 | #ifdef __OBJC__ 12 | #import 13 | #import 14 | #endif 15 | -------------------------------------------------------------------------------- /Examples/GCD/ConnectTest/Mobile/ConnectTest/ConnectTestAppDelegate.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | @class ConnectTestViewController; 4 | @class GCDAsyncSocket; 5 | 6 | 7 | @interface ConnectTestAppDelegate : NSObject 8 | { 9 | GCDAsyncSocket *asyncSocket; 10 | } 11 | 12 | @property (nonatomic, strong) IBOutlet UIWindow *window; 13 | @property (nonatomic, strong) IBOutlet ConnectTestViewController *viewController; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /Examples/GCD/ConnectTest/Mobile/ConnectTest/ConnectTestViewController.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | 4 | @interface ConnectTestViewController : UIViewController { 5 | 6 | } 7 | 8 | @property (nonatomic, strong) IBOutlet UILabel *label; 9 | 10 | @end 11 | -------------------------------------------------------------------------------- /Examples/GCD/ConnectTest/Mobile/ConnectTest/ConnectTestViewController.m: -------------------------------------------------------------------------------- 1 | #import "ConnectTestViewController.h" 2 | 3 | 4 | @implementation ConnectTestViewController 5 | 6 | @synthesize label = _label; 7 | 8 | 9 | @end 10 | -------------------------------------------------------------------------------- /Examples/GCD/ConnectTest/Mobile/ConnectTest/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /Examples/GCD/ConnectTest/Mobile/ConnectTest/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // ConnectTest 4 | // 5 | // Created by Robbie Hanson on 7/25/11. 6 | // Copyright 2011 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | int main(int argc, char *argv[]) 12 | { 13 | @autoreleasepool { 14 | int retVal = UIApplicationMain(argc, argv, nil, nil); 15 | return retVal; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Examples/GCD/ConnectTest/Mobile/Default-568h@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/52im/CocoaAsyncSocket/562bae6af6dbd7e1891293dae20b9f79a2fd7228/Examples/GCD/ConnectTest/Mobile/Default-568h@2x.png -------------------------------------------------------------------------------- /Examples/GCD/ConnectTest/ReadMe.txt: -------------------------------------------------------------------------------- 1 | The ConnectTest projects demonstrates some of the various options available for connecting to a host, such as: 2 | 3 | - Setting connect timeouts 4 | - Connecting to secure hosts (using SSL/TLS) -------------------------------------------------------------------------------- /Examples/GCD/DomainTest/DomainTest.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Examples/GCD/DomainTest/DomainTest/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // DomainTest 4 | // 5 | // Created by Jonathan Diehl on 06.10.12. 6 | // Copyright (c) 2012 Jonathan Diehl. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "DomainServer.h" 12 | #import "DomainClient.h" 13 | 14 | @interface AppDelegate : NSObject 15 | 16 | @property (assign) IBOutlet NSWindow *window; 17 | @property (strong) DomainServer *server; 18 | @property (strong) NSMutableArray *clients; 19 | 20 | - (IBAction)addClient:(id)sender; 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /Examples/GCD/DomainTest/DomainTest/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // DomainTest 4 | // 5 | // Created by Jonathan Diehl on 06.10.12. 6 | // Copyright (c) 2012 Jonathan Diehl. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @implementation AppDelegate 12 | 13 | @synthesize server = _server; 14 | @synthesize clients = _clients; 15 | 16 | - (IBAction)addClient:(id)sender; 17 | { 18 | DomainClient *client = [[DomainClient alloc] initWithWindowNibName:@"DomainClient"]; 19 | [self.clients addObject:client]; 20 | [client connectToUrl:self.server.url]; 21 | [client showWindow:sender]; 22 | } 23 | 24 | - (void)applicationDidFinishLaunching:(NSNotification *)aNotification 25 | { 26 | _clients = [NSMutableArray new]; 27 | 28 | NSError *error = nil; 29 | _server = [DomainServer new]; 30 | self.server.url = [NSURL fileURLWithPath:@"/tmp/socket"]; 31 | if (![self.server start:&error]) { 32 | [self.window presentError:error]; 33 | } 34 | 35 | [self addClient:nil]; 36 | } 37 | 38 | @end 39 | -------------------------------------------------------------------------------- /Examples/GCD/DomainTest/DomainTest/DomainClient.h: -------------------------------------------------------------------------------- 1 | // 2 | // DomainClient.h 3 | // DomainTest 4 | // 5 | // Created by Jonathan Diehl on 06.10.12. 6 | // Copyright (c) 2012 Jonathan Diehl. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "GCDAsyncSocket.h" 12 | 13 | @interface DomainClient : NSWindowController 14 | 15 | @property (readonly) GCDAsyncSocket *socket; 16 | @property (strong) IBOutlet NSTextView *outputView; 17 | @property (strong) IBOutlet NSTextField *inputView; 18 | 19 | - (void)connectToUrl:(NSURL *)url; 20 | - (IBAction)send:(id)sender; 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /Examples/GCD/DomainTest/DomainTest/DomainClient.m: -------------------------------------------------------------------------------- 1 | // 2 | // DomainClient.m 3 | // DomainTest 4 | // 5 | // Created by Jonathan Diehl on 06.10.12. 6 | // Copyright (c) 2012 Jonathan Diehl. All rights reserved. 7 | // 8 | 9 | #import "DomainClient.h" 10 | 11 | @implementation DomainClient 12 | 13 | @synthesize socket = _socket; 14 | @synthesize outputView = _outputView; 15 | @synthesize inputView = _inputView; 16 | 17 | - (void)connectToUrl:(NSURL *)url; 18 | { 19 | NSError *error = nil; 20 | _socket = [[GCDAsyncSocket alloc] initWithDelegate:self delegateQueue:dispatch_get_main_queue()]; 21 | if (![self.socket connectToUrl:url withTimeout:-1 error:&error]) { 22 | [self presentError:error]; 23 | } 24 | } 25 | 26 | - (IBAction)send:(id)sender; 27 | { 28 | NSData *data = [self.inputView.stringValue dataUsingEncoding:NSUTF8StringEncoding]; 29 | [self.socket writeData:data withTimeout:-1 tag:0]; 30 | self.inputView.stringValue = @""; 31 | } 32 | 33 | - (void)socket:(GCDAsyncSocket *)sock didConnectToUrl:(NSURL *)url; 34 | { 35 | NSLog(@"[Client] Connected to %@", url); 36 | [sock readDataWithTimeout:-1 tag:0]; 37 | } 38 | 39 | - (void)socketDidDisconnect:(GCDAsyncSocket *)socket withError:(NSError *)error; 40 | { 41 | NSLog(@"[Client] Closed connection: %@", error); 42 | } 43 | 44 | - (void)socket:(GCDAsyncSocket *)sock didReadData:(NSData *)data withTag:(long)tag; 45 | { 46 | NSString *text = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; 47 | NSLog(@"[Client] Received: %@", text); 48 | 49 | text = [text stringByAppendingString:@"\n"]; 50 | NSAttributedString *string = [[NSAttributedString alloc] initWithString:text]; 51 | NSTextStorage *storage = self.outputView.textStorage; 52 | 53 | [storage beginEditing]; 54 | [storage appendAttributedString:string]; 55 | [storage endEditing]; 56 | 57 | [sock readDataWithTimeout:-1 tag:0]; 58 | } 59 | 60 | @end 61 | -------------------------------------------------------------------------------- /Examples/GCD/DomainTest/DomainTest/DomainServer.h: -------------------------------------------------------------------------------- 1 | // 2 | // DomainServer.h 3 | // DomainTest 4 | // 5 | // Created by Jonathan Diehl on 06.10.12. 6 | // Copyright (c) 2012 Jonathan Diehl. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "GCDAsyncSocket.h" 12 | 13 | @interface DomainServer : NSObject 14 | 15 | @property (readonly) GCDAsyncSocket *socket; 16 | @property (readonly) NSMutableSet *connectedSockets; 17 | @property (strong) NSURL *url; 18 | 19 | - (BOOL)start:(NSError **)error; 20 | - (void)stop; 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /Examples/GCD/DomainTest/DomainTest/DomainServer.m: -------------------------------------------------------------------------------- 1 | // 2 | // DomainServer.m 3 | // DomainTest 4 | // 5 | // Created by Jonathan Diehl on 06.10.12. 6 | // Copyright (c) 2012 Jonathan Diehl. All rights reserved. 7 | // 8 | 9 | #import "DomainServer.h" 10 | 11 | @implementation DomainServer 12 | 13 | @synthesize socket = _socket; 14 | @synthesize url = _url; 15 | 16 | - (BOOL)start:(NSError **)error; 17 | { 18 | _connectedSockets = [NSMutableSet new]; 19 | _socket = [[GCDAsyncSocket alloc] initWithDelegate:self delegateQueue:dispatch_get_main_queue()]; 20 | BOOL result = [self.socket acceptOnUrl:self.url error:error]; 21 | if (result) { 22 | NSLog(@"[Server] Started at: %@", self.url.path); 23 | } 24 | return result; 25 | } 26 | 27 | - (void)stop; 28 | { 29 | _socket = nil; 30 | NSLog(@"[Server] Stopped."); 31 | } 32 | 33 | - (void)socket:(GCDAsyncSocket *)sock didAcceptNewSocket:(GCDAsyncSocket *)newSocket; 34 | { 35 | NSLog(@"[Server] New connection."); 36 | [self.connectedSockets addObject:newSocket]; 37 | [newSocket readDataWithTimeout:-1 tag:0]; 38 | } 39 | 40 | - (void)socketDidDisconnect:(GCDAsyncSocket *)socket withError:(NSError *)error; 41 | { 42 | [self.connectedSockets removeObject:socket]; 43 | NSLog(@"[Server] Closed connection: %@", error); 44 | } 45 | 46 | - (void)socket:(GCDAsyncSocket *)sock didReadData:(NSData *)data withTag:(long)tag; 47 | { 48 | NSString *text = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; 49 | NSLog(@"[Server] Received: %@", text); 50 | 51 | [sock writeData:data withTimeout:-1 tag:0]; 52 | [sock readDataWithTimeout:-1 tag:0]; 53 | } 54 | 55 | @end 56 | -------------------------------------------------------------------------------- /Examples/GCD/DomainTest/DomainTest/DomainTest-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIconFile 10 | 11 | CFBundleIdentifier 12 | com.yourcompany.${PRODUCT_NAME:rfc1034identifier} 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1 25 | LSMinimumSystemVersion 26 | ${MACOSX_DEPLOYMENT_TARGET} 27 | NSHumanReadableCopyright 28 | Copyright © 2012 Jonathan Diehl. All rights reserved. 29 | NSMainNibFile 30 | MainMenu 31 | NSPrincipalClass 32 | NSApplication 33 | 34 | 35 | -------------------------------------------------------------------------------- /Examples/GCD/DomainTest/DomainTest/DomainTest-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'DomainTest' target in the 'DomainTest' project 3 | // 4 | 5 | #ifdef __OBJC__ 6 | #import 7 | #endif 8 | -------------------------------------------------------------------------------- /Examples/GCD/DomainTest/DomainTest/en.lproj/Credits.rtf: -------------------------------------------------------------------------------- 1 | {\rtf0\ansi{\fonttbl\f0\fswiss Helvetica;} 2 | {\colortbl;\red255\green255\blue255;} 3 | \paperw9840\paperh8400 4 | \pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural 5 | 6 | \f0\b\fs24 \cf0 Engineering: 7 | \b0 \ 8 | Some people\ 9 | \ 10 | 11 | \b Human Interface Design: 12 | \b0 \ 13 | Some other people\ 14 | \ 15 | 16 | \b Testing: 17 | \b0 \ 18 | Hopefully not nobody\ 19 | \ 20 | 21 | \b Documentation: 22 | \b0 \ 23 | Whoever\ 24 | \ 25 | 26 | \b With special thanks to: 27 | \b0 \ 28 | Mom\ 29 | } 30 | -------------------------------------------------------------------------------- /Examples/GCD/DomainTest/DomainTest/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /Examples/GCD/DomainTest/DomainTest/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // DomainTest 4 | // 5 | // Created by Jonathan Diehl on 06.10.12. 6 | // Copyright (c) 2012 Jonathan Diehl. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | int main(int argc, char *argv[]) 12 | { 13 | return NSApplicationMain(argc, (const char **)argv); 14 | } 15 | -------------------------------------------------------------------------------- /Examples/GCD/EchoServer/EchoServer-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIconFile 10 | 11 | CFBundleIdentifier 12 | com.yourcompany.${PRODUCT_NAME:rfc1034identifier} 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1 25 | LSMinimumSystemVersion 26 | ${MACOSX_DEPLOYMENT_TARGET} 27 | NSMainNibFile 28 | MainMenu 29 | NSPrincipalClass 30 | NSApplication 31 | 32 | 33 | -------------------------------------------------------------------------------- /Examples/GCD/EchoServer/EchoServer.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Examples/GCD/EchoServer/EchoServerAppDelegate.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | @class GCDAsyncSocket; 4 | 5 | 6 | @interface EchoServerAppDelegate : NSObject 7 | { 8 | dispatch_queue_t socketQueue; 9 | 10 | GCDAsyncSocket *listenSocket; 11 | NSMutableArray *connectedSockets; 12 | 13 | BOOL isRunning; 14 | 15 | IBOutlet id logView; 16 | IBOutlet id portField; 17 | IBOutlet id startStopButton; 18 | 19 | NSWindow *__unsafe_unretained window; 20 | } 21 | 22 | @property (unsafe_unretained) IBOutlet NSWindow *window; 23 | 24 | - (IBAction)startStop:(id)sender; 25 | 26 | @end 27 | -------------------------------------------------------------------------------- /Examples/GCD/EchoServer/EchoServer_Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'EchoServer' target in the 'EchoServer' project 3 | // 4 | 5 | #ifdef __OBJC__ 6 | #import 7 | #endif 8 | -------------------------------------------------------------------------------- /Examples/GCD/EchoServer/English.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /Examples/GCD/EchoServer/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // EchoServer 4 | // 5 | // Created by Robbie Hanson on 11/4/10. 6 | // Copyright 2010 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | int main(int argc, char *argv[]) 12 | { 13 | return NSApplicationMain(argc, (const char **) argv); 14 | } 15 | -------------------------------------------------------------------------------- /Examples/GCD/SimpleHTTPClient/Desktop/SimpleHTTPClient.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Examples/GCD/SimpleHTTPClient/Desktop/SimpleHTTPClient/SimpleHTTPClient-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIconFile 10 | 11 | CFBundleIdentifier 12 | com.deusty.${PRODUCT_NAME:rfc1034identifier} 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1 25 | LSMinimumSystemVersion 26 | ${MACOSX_DEPLOYMENT_TARGET} 27 | NSMainNibFile 28 | MainMenu 29 | NSPrincipalClass 30 | NSApplication 31 | 32 | 33 | -------------------------------------------------------------------------------- /Examples/GCD/SimpleHTTPClient/Desktop/SimpleHTTPClient/SimpleHTTPClient-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'SimpleHTTPClient' target in the 'SimpleHTTPClient' project 3 | // 4 | 5 | #ifdef __OBJC__ 6 | #import 7 | #endif 8 | -------------------------------------------------------------------------------- /Examples/GCD/SimpleHTTPClient/Desktop/SimpleHTTPClient/SimpleHTTPClientAppDelegate.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | @class GCDAsyncSocket; 4 | 5 | 6 | @interface SimpleHTTPClientAppDelegate : NSObject { 7 | @private 8 | GCDAsyncSocket *asyncSocket; 9 | 10 | NSWindow *__unsafe_unretained window; 11 | } 12 | 13 | @property (unsafe_unretained) IBOutlet NSWindow *window; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /Examples/GCD/SimpleHTTPClient/Desktop/SimpleHTTPClient/en.lproj/Credits.rtf: -------------------------------------------------------------------------------- 1 | {\rtf0\ansi{\fonttbl\f0\fswiss Helvetica;} 2 | {\colortbl;\red255\green255\blue255;} 3 | \paperw9840\paperh8400 4 | \pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural 5 | 6 | \f0\b\fs24 \cf0 Engineering: 7 | \b0 \ 8 | Some people\ 9 | \ 10 | 11 | \b Human Interface Design: 12 | \b0 \ 13 | Some other people\ 14 | \ 15 | 16 | \b Testing: 17 | \b0 \ 18 | Hopefully not nobody\ 19 | \ 20 | 21 | \b Documentation: 22 | \b0 \ 23 | Whoever\ 24 | \ 25 | 26 | \b With special thanks to: 27 | \b0 \ 28 | Mom\ 29 | } 30 | -------------------------------------------------------------------------------- /Examples/GCD/SimpleHTTPClient/Desktop/SimpleHTTPClient/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /Examples/GCD/SimpleHTTPClient/Desktop/SimpleHTTPClient/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // SimpleHTTPClient 4 | // 5 | // Created by Robbie Hanson on 7/5/11. 6 | // Copyright 2011 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | int main(int argc, char *argv[]) 12 | { 13 | return NSApplicationMain(argc, (const char **)argv); 14 | } 15 | -------------------------------------------------------------------------------- /Examples/GCD/SimpleHTTPClient/Mobile/Default-568h@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/52im/CocoaAsyncSocket/562bae6af6dbd7e1891293dae20b9f79a2fd7228/Examples/GCD/SimpleHTTPClient/Mobile/Default-568h@2x.png -------------------------------------------------------------------------------- /Examples/GCD/SimpleHTTPClient/Mobile/SimpleHTTPClient.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Examples/GCD/SimpleHTTPClient/Mobile/SimpleHTTPClient/SimpleHTTPClient-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDisplayName 8 | ${PRODUCT_NAME} 9 | CFBundleExecutable 10 | ${EXECUTABLE_NAME} 11 | CFBundleIconFile 12 | 13 | CFBundleIdentifier 14 | com.deusty.${PRODUCT_NAME:rfc1034identifier} 15 | CFBundleInfoDictionaryVersion 16 | 6.0 17 | CFBundleName 18 | ${PRODUCT_NAME} 19 | CFBundlePackageType 20 | APPL 21 | CFBundleShortVersionString 22 | 1.0 23 | CFBundleSignature 24 | ???? 25 | CFBundleVersion 26 | 1.0 27 | LSRequiresIPhoneOS 28 | 29 | NSMainNibFile 30 | MainWindow 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /Examples/GCD/SimpleHTTPClient/Mobile/SimpleHTTPClient/SimpleHTTPClient-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'SimpleHTTPClient' target in the 'SimpleHTTPClient' project 3 | // 4 | 5 | #import 6 | 7 | #ifndef __IPHONE_3_0 8 | #warning "This project uses features only available in iPhone SDK 3.0 and later." 9 | #endif 10 | 11 | #ifdef __OBJC__ 12 | #import 13 | #import 14 | #endif 15 | -------------------------------------------------------------------------------- /Examples/GCD/SimpleHTTPClient/Mobile/SimpleHTTPClient/SimpleHTTPClientAppDelegate.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | @class SimpleHTTPClientViewController; 4 | @class GCDAsyncSocket; 5 | 6 | 7 | @interface SimpleHTTPClientAppDelegate : NSObject 8 | { 9 | GCDAsyncSocket *asyncSocket; 10 | } 11 | 12 | @property (nonatomic) IBOutlet UIWindow *window; 13 | @property (nonatomic) IBOutlet SimpleHTTPClientViewController *viewController; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /Examples/GCD/SimpleHTTPClient/Mobile/SimpleHTTPClient/SimpleHTTPClientViewController.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | 4 | @interface SimpleHTTPClientViewController : UIViewController { 5 | 6 | } 7 | 8 | @end 9 | -------------------------------------------------------------------------------- /Examples/GCD/SimpleHTTPClient/Mobile/SimpleHTTPClient/SimpleHTTPClientViewController.m: -------------------------------------------------------------------------------- 1 | #import "SimpleHTTPClientViewController.h" 2 | 3 | 4 | @implementation SimpleHTTPClientViewController 5 | 6 | @end 7 | -------------------------------------------------------------------------------- /Examples/GCD/SimpleHTTPClient/Mobile/SimpleHTTPClient/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /Examples/GCD/SimpleHTTPClient/Mobile/SimpleHTTPClient/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // SimpleHTTPClient 4 | // 5 | // Created by Robbie Hanson on 7/5/11. 6 | // Copyright 2011 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | int main(int argc, char *argv[]) 12 | { 13 | @autoreleasepool { 14 | int retVal = UIApplicationMain(argc, argv, nil, nil); 15 | return retVal; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Examples/GCD/SimpleHTTPClient/ReadMe.txt: -------------------------------------------------------------------------------- 1 | The SimpleHTTPClient projects are just a simple demonstration of reading and writing data using GCDAsyncSocket. Obviously it's not meant to be a full fledged HTTP client. There are other excellent libraries for that task. But the HTTP protocol itself is so simple, it makes for a great example. -------------------------------------------------------------------------------- /Examples/GCD/TestPreBuffer/Desktop/TestPreBuffer.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Examples/GCD/TestPreBuffer/Desktop/TestPreBuffer/AppDelegate.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | 4 | @interface AppDelegate : NSObject 5 | 6 | @property (assign) IBOutlet NSWindow *window; 7 | 8 | @end 9 | -------------------------------------------------------------------------------- /Examples/GCD/TestPreBuffer/Desktop/TestPreBuffer/AppDelegate.m: -------------------------------------------------------------------------------- 1 | #import "AppDelegate.h" 2 | #import "TestPreBuffer.h" 3 | 4 | 5 | @implementation AppDelegate 6 | 7 | @synthesize window = _window; 8 | 9 | - (void)applicationDidFinishLaunching:(NSNotification *)aNotification 10 | { 11 | [TestPreBuffer start]; 12 | } 13 | 14 | @end 15 | -------------------------------------------------------------------------------- /Examples/GCD/TestPreBuffer/Desktop/TestPreBuffer/TestPreBuffer-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIconFile 10 | 11 | CFBundleIdentifier 12 | com.deusty.${PRODUCT_NAME:rfc1034identifier} 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1 25 | LSMinimumSystemVersion 26 | ${MACOSX_DEPLOYMENT_TARGET} 27 | NSHumanReadableCopyright 28 | Copyright © 2012 __MyCompanyName__. All rights reserved. 29 | NSMainNibFile 30 | MainMenu 31 | NSPrincipalClass 32 | NSApplication 33 | 34 | 35 | -------------------------------------------------------------------------------- /Examples/GCD/TestPreBuffer/Desktop/TestPreBuffer/TestPreBuffer-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'TestPreBuffer' target in the 'TestPreBuffer' project 3 | // 4 | 5 | #ifdef __OBJC__ 6 | #import 7 | #endif 8 | -------------------------------------------------------------------------------- /Examples/GCD/TestPreBuffer/Desktop/TestPreBuffer/en.lproj/Credits.rtf: -------------------------------------------------------------------------------- 1 | {\rtf0\ansi{\fonttbl\f0\fswiss Helvetica;} 2 | {\colortbl;\red255\green255\blue255;} 3 | \paperw9840\paperh8400 4 | \pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural 5 | 6 | \f0\b\fs24 \cf0 Engineering: 7 | \b0 \ 8 | Some people\ 9 | \ 10 | 11 | \b Human Interface Design: 12 | \b0 \ 13 | Some other people\ 14 | \ 15 | 16 | \b Testing: 17 | \b0 \ 18 | Hopefully not nobody\ 19 | \ 20 | 21 | \b Documentation: 22 | \b0 \ 23 | Whoever\ 24 | \ 25 | 26 | \b With special thanks to: 27 | \b0 \ 28 | Mom\ 29 | } 30 | -------------------------------------------------------------------------------- /Examples/GCD/TestPreBuffer/Desktop/TestPreBuffer/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /Examples/GCD/TestPreBuffer/Desktop/TestPreBuffer/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // TestPreBuffer 4 | // 5 | // Created by Robbie Hanson on 6/7/12. 6 | // Copyright (c) 2012 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | int main(int argc, char *argv[]) 12 | { 13 | return NSApplicationMain(argc, (const char **)argv); 14 | } 15 | -------------------------------------------------------------------------------- /Examples/GCD/TestPreBuffer/Mobile/Default-568h@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/52im/CocoaAsyncSocket/562bae6af6dbd7e1891293dae20b9f79a2fd7228/Examples/GCD/TestPreBuffer/Mobile/Default-568h@2x.png -------------------------------------------------------------------------------- /Examples/GCD/TestPreBuffer/Mobile/TestPreBuffer.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Examples/GCD/TestPreBuffer/Mobile/TestPreBuffer/AppDelegate.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | @class ViewController; 4 | 5 | 6 | @interface AppDelegate : UIResponder 7 | 8 | @property (strong, nonatomic) UIWindow *window; 9 | @property (strong, nonatomic) ViewController *viewController; 10 | 11 | @end 12 | -------------------------------------------------------------------------------- /Examples/GCD/TestPreBuffer/Mobile/TestPreBuffer/AppDelegate.m: -------------------------------------------------------------------------------- 1 | #import "AppDelegate.h" 2 | #import "ViewController.h" 3 | #import "TestPreBuffer.h" 4 | 5 | 6 | @implementation AppDelegate 7 | 8 | @synthesize window; 9 | @synthesize viewController; 10 | 11 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 12 | { 13 | [TestPreBuffer start]; 14 | 15 | // Normal UI stuff 16 | 17 | window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 18 | if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { 19 | viewController = [[ViewController alloc] initWithNibName:@"ViewController_iPhone" bundle:nil]; 20 | } else { 21 | viewController = [[ViewController alloc] initWithNibName:@"ViewController_iPad" bundle:nil]; 22 | } 23 | window.rootViewController = self.viewController; 24 | [window makeKeyAndVisible]; 25 | return YES; 26 | } 27 | 28 | @end 29 | -------------------------------------------------------------------------------- /Examples/GCD/TestPreBuffer/Mobile/TestPreBuffer/TestPreBuffer-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDisplayName 8 | ${PRODUCT_NAME} 9 | CFBundleExecutable 10 | ${EXECUTABLE_NAME} 11 | CFBundleIdentifier 12 | com.deusty.${PRODUCT_NAME:rfc1034identifier} 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1.0 25 | LSRequiresIPhoneOS 26 | 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | UISupportedInterfaceOrientations~ipad 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationPortraitUpsideDown 41 | UIInterfaceOrientationLandscapeLeft 42 | UIInterfaceOrientationLandscapeRight 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /Examples/GCD/TestPreBuffer/Mobile/TestPreBuffer/TestPreBuffer-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'TestPreBuffer' target in the 'TestPreBuffer' project 3 | // 4 | 5 | #import 6 | 7 | #ifndef __IPHONE_4_0 8 | #warning "This project uses features only available in iOS SDK 4.0 and later." 9 | #endif 10 | 11 | #ifdef __OBJC__ 12 | #import 13 | #import 14 | #endif 15 | -------------------------------------------------------------------------------- /Examples/GCD/TestPreBuffer/Mobile/TestPreBuffer/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // TestPreBuffer 4 | // 5 | // Created by Robbie Hanson on 6/7/12. 6 | // Copyright (c) 2012 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /Examples/GCD/TestPreBuffer/Mobile/TestPreBuffer/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // TestPreBuffer 4 | // 5 | // Created by Robbie Hanson on 6/7/12. 6 | // Copyright (c) 2012 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | 11 | @interface ViewController () 12 | 13 | @end 14 | 15 | @implementation ViewController 16 | 17 | - (void)viewDidLoad 18 | { 19 | [super viewDidLoad]; 20 | // Do any additional setup after loading the view, typically from a nib. 21 | } 22 | 23 | - (void)viewDidUnload 24 | { 25 | [super viewDidUnload]; 26 | // Release any retained subviews of the main view. 27 | } 28 | 29 | - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 30 | { 31 | if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { 32 | return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown); 33 | } else { 34 | return YES; 35 | } 36 | } 37 | 38 | @end 39 | -------------------------------------------------------------------------------- /Examples/GCD/TestPreBuffer/Mobile/TestPreBuffer/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /Examples/GCD/TestPreBuffer/Mobile/TestPreBuffer/en.lproj/ViewController_iPad.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 1280 5 | 11C25 6 | 1919 7 | 1138.11 8 | 566.00 9 | 10 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 11 | 916 12 | 13 | 14 | IBProxyObject 15 | IBUIView 16 | 17 | 18 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 19 | 20 | 21 | PluginDependencyRecalculationVersion 22 | 23 | 24 | 25 | 26 | IBFilesOwner 27 | IBIPadFramework 28 | 29 | 30 | IBFirstResponder 31 | IBIPadFramework 32 | 33 | 34 | 35 | 274 36 | {{0, 20}, {768, 1004}} 37 | 38 | 39 | 40 | 3 41 | MQA 42 | 43 | 2 44 | 45 | 46 | 47 | 2 48 | 49 | IBIPadFramework 50 | 51 | 52 | 53 | 54 | 55 | 56 | view 57 | 58 | 59 | 60 | 3 61 | 62 | 63 | 64 | 65 | 66 | 0 67 | 68 | 69 | 70 | 71 | 72 | -1 73 | 74 | 75 | File's Owner 76 | 77 | 78 | -2 79 | 80 | 81 | 82 | 83 | 2 84 | 85 | 86 | 87 | 88 | 89 | 90 | ViewController 91 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 92 | UIResponder 93 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 94 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 95 | 96 | 97 | 98 | 99 | 100 | 3 101 | 102 | 103 | 104 | 105 | ViewController 106 | UIViewController 107 | 108 | IBProjectSource 109 | ./Classes/ViewController.h 110 | 111 | 112 | 113 | 114 | 0 115 | IBIPadFramework 116 | YES 117 | 3 118 | 916 119 | 120 | 121 | -------------------------------------------------------------------------------- /Examples/GCD/TestPreBuffer/Mobile/TestPreBuffer/en.lproj/ViewController_iPhone.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 1280 5 | 11C25 6 | 1919 7 | 1138.11 8 | 566.00 9 | 10 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 11 | 916 12 | 13 | 14 | IBProxyObject 15 | IBUIView 16 | 17 | 18 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 19 | 20 | 21 | PluginDependencyRecalculationVersion 22 | 23 | 24 | 25 | 26 | IBFilesOwner 27 | IBCocoaTouchFramework 28 | 29 | 30 | IBFirstResponder 31 | IBCocoaTouchFramework 32 | 33 | 34 | 35 | 274 36 | {{0, 20}, {320, 460}} 37 | 38 | 39 | 40 | 3 41 | MC43NQA 42 | 43 | 2 44 | 45 | 46 | NO 47 | 48 | IBCocoaTouchFramework 49 | 50 | 51 | 52 | 53 | 54 | 55 | view 56 | 57 | 58 | 59 | 7 60 | 61 | 62 | 63 | 64 | 65 | 0 66 | 67 | 68 | 69 | 70 | 71 | -1 72 | 73 | 74 | File's Owner 75 | 76 | 77 | -2 78 | 79 | 80 | 81 | 82 | 6 83 | 84 | 85 | 86 | 87 | 88 | 89 | ViewController 90 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 91 | UIResponder 92 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 93 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 94 | 95 | 96 | 97 | 98 | 99 | 7 100 | 101 | 102 | 103 | 104 | ViewController 105 | UIViewController 106 | 107 | IBProjectSource 108 | ./Classes/ViewController.h 109 | 110 | 111 | 112 | 113 | 0 114 | IBCocoaTouchFramework 115 | YES 116 | 3 117 | 916 118 | 119 | 120 | -------------------------------------------------------------------------------- /Examples/GCD/TestPreBuffer/Mobile/TestPreBuffer/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // TestPreBuffer 4 | // 5 | // Created by Robbie Hanson on 6/7/12. 6 | // Copyright (c) 2012 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "AppDelegate.h" 12 | 13 | int main(int argc, char *argv[]) 14 | { 15 | @autoreleasepool { 16 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Examples/GCD/TestPreBuffer/Shared/TestPreBuffer.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | 4 | @interface TestPreBuffer : NSObject 5 | 6 | + (void)start; 7 | 8 | @end 9 | -------------------------------------------------------------------------------- /Examples/GCD/UdpEchoClient/Desktop/UdpEchoClient.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Examples/GCD/UdpEchoClient/Desktop/UdpEchoClient/AppDelegate.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import "GCDAsyncUdpSocket.h" 3 | 4 | @interface AppDelegate : NSObject 5 | { 6 | long tag; 7 | GCDAsyncUdpSocket *udpSocket; 8 | } 9 | 10 | @property (unsafe_unretained) IBOutlet NSWindow * window; 11 | @property IBOutlet NSTextField * addrField; 12 | @property IBOutlet NSTextField * portField; 13 | @property IBOutlet NSTextField * messageField; 14 | @property IBOutlet NSButton * sendButton; 15 | @property IBOutlet NSTextView * logView; 16 | 17 | - (IBAction)send:(id)sender; 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /Examples/GCD/UdpEchoClient/Desktop/UdpEchoClient/AppDelegate.m: -------------------------------------------------------------------------------- 1 | #import "AppDelegate.h" 2 | #import "DDLog.h" 3 | #import "DDTTYLogger.h" 4 | #import "GCDAsyncUdpSocket.h" 5 | 6 | // Log levels: off, error, warn, info, verbose 7 | static const int ddLogLevel = LOG_LEVEL_VERBOSE; 8 | 9 | #define FORMAT(format, ...) [NSString stringWithFormat:(format), ##__VA_ARGS__] 10 | 11 | 12 | @implementation AppDelegate 13 | 14 | @synthesize window = _window; 15 | @synthesize addrField; 16 | @synthesize portField; 17 | @synthesize messageField; 18 | @synthesize sendButton; 19 | @synthesize logView; 20 | 21 | - (void)applicationDidFinishLaunching:(NSNotification *)aNotification 22 | { 23 | // Setup our logging framework. 24 | 25 | [DDLog addLogger:[DDTTYLogger sharedInstance]]; 26 | 27 | // Setup our socket. 28 | // The socket will invoke our delegate methods using the usual delegate paradigm. 29 | // However, it will invoke the delegate methods on a specified GCD delegate dispatch queue. 30 | // 31 | // Now we can configure the delegate dispatch queues however we want. 32 | // We could simply use the main dispatc queue, so the delegate methods are invoked on the main thread. 33 | // Or we could use a dedicated dispatch queue, which could be helpful if we were doing a lot of processing. 34 | // 35 | // The best approach for your application will depend upon convenience, requirements and performance. 36 | // 37 | // For this simple example, we're just going to use the main thread. 38 | 39 | udpSocket = [[GCDAsyncUdpSocket alloc] initWithDelegate:self delegateQueue:dispatch_get_main_queue()]; 40 | 41 | NSError *error = nil; 42 | 43 | if (![udpSocket bindToPort:0 error:&error]) 44 | { 45 | DDLogError(@"Error binding: %@", error); 46 | return; 47 | } 48 | if (![udpSocket beginReceiving:&error]) 49 | { 50 | DDLogError(@"Error receiving: %@", error); 51 | return; 52 | } 53 | 54 | DDLogVerbose(@"Ready"); 55 | } 56 | 57 | - (void)scrollToBottom 58 | { 59 | NSScrollView *scrollView = [logView enclosingScrollView]; 60 | NSPoint newScrollOrigin; 61 | 62 | if ([[scrollView documentView] isFlipped]) 63 | newScrollOrigin = NSMakePoint(0.0F, NSMaxY([[scrollView documentView] frame])); 64 | else 65 | newScrollOrigin = NSMakePoint(0.0F, 0.0F); 66 | 67 | [[scrollView documentView] scrollPoint:newScrollOrigin]; 68 | } 69 | 70 | - (void)logError:(NSString *)msg 71 | { 72 | NSString *paragraph = [NSString stringWithFormat:@"%@\n", msg]; 73 | 74 | NSMutableDictionary *attributes = [NSMutableDictionary dictionaryWithCapacity:1]; 75 | [attributes setObject:[NSColor redColor] forKey:NSForegroundColorAttributeName]; 76 | 77 | NSAttributedString *as = [[NSAttributedString alloc] initWithString:paragraph attributes:attributes]; 78 | 79 | [[logView textStorage] appendAttributedString:as]; 80 | [self scrollToBottom]; 81 | } 82 | 83 | - (void)logInfo:(NSString *)msg 84 | { 85 | NSString *paragraph = [NSString stringWithFormat:@"%@\n", msg]; 86 | 87 | NSMutableDictionary *attributes = [NSMutableDictionary dictionaryWithCapacity:1]; 88 | [attributes setObject:[NSColor purpleColor] forKey:NSForegroundColorAttributeName]; 89 | 90 | NSAttributedString *as = [[NSAttributedString alloc] initWithString:paragraph attributes:attributes]; 91 | 92 | [[logView textStorage] appendAttributedString:as]; 93 | [self scrollToBottom]; 94 | } 95 | 96 | - (void)logMessage:(NSString *)msg 97 | { 98 | NSString *paragraph = [NSString stringWithFormat:@"%@\n", msg]; 99 | 100 | NSMutableDictionary *attributes = [NSMutableDictionary dictionaryWithCapacity:1]; 101 | [attributes setObject:[NSColor blackColor] forKey:NSForegroundColorAttributeName]; 102 | 103 | NSAttributedString *as = [[NSAttributedString alloc] initWithString:paragraph attributes:attributes]; 104 | 105 | [[logView textStorage] appendAttributedString:as]; 106 | [self scrollToBottom]; 107 | } 108 | 109 | - (IBAction)send:(id)sender 110 | { 111 | NSString *host = [addrField stringValue]; 112 | if ([host length] == 0) 113 | { 114 | [self logError:@"Address required"]; 115 | return; 116 | } 117 | 118 | int port = [portField intValue]; 119 | if (port <= 0 || port > 65535) 120 | { 121 | [self logError:@"Valid port required"]; 122 | return; 123 | } 124 | 125 | NSString *msg = [messageField stringValue]; 126 | if ([msg length] == 0) 127 | { 128 | [self logError:@"Message required"]; 129 | return; 130 | } 131 | 132 | NSData *data = [msg dataUsingEncoding:NSUTF8StringEncoding]; 133 | [udpSocket sendData:data toHost:host port:port withTimeout:-1 tag:tag]; 134 | 135 | [self logMessage:FORMAT(@"SENT (%i): %@", (int)tag, msg)]; 136 | 137 | tag++; 138 | } 139 | 140 | - (void)udpSocket:(GCDAsyncUdpSocket *)sock didSendDataWithTag:(long)tag 141 | { 142 | // You could add checks here 143 | } 144 | 145 | - (void)udpSocket:(GCDAsyncUdpSocket *)sock didNotSendDataWithTag:(long)tag dueToError:(NSError *)error 146 | { 147 | // You could add checks here 148 | } 149 | 150 | - (void)udpSocket:(GCDAsyncUdpSocket *)sock didReceiveData:(NSData *)data 151 | fromAddress:(NSData *)address 152 | withFilterContext:(id)filterContext 153 | { 154 | NSString *msg = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; 155 | if (msg) 156 | { 157 | [self logMessage:FORMAT(@"RECV: %@", msg)]; 158 | } 159 | else 160 | { 161 | NSString *host = nil; 162 | uint16_t port = 0; 163 | [GCDAsyncUdpSocket getHost:&host port:&port fromAddress:address]; 164 | 165 | [self logInfo:FORMAT(@"RECV: Unknown message from: %@:%hu", host, port)]; 166 | } 167 | } 168 | 169 | @end 170 | -------------------------------------------------------------------------------- /Examples/GCD/UdpEchoClient/Desktop/UdpEchoClient/UdpEchoClient-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIconFile 10 | 11 | CFBundleIdentifier 12 | com.deusty.oss.${PRODUCT_NAME:rfc1034identifier} 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1 25 | LSMinimumSystemVersion 26 | ${MACOSX_DEPLOYMENT_TARGET} 27 | NSHumanReadableCopyright 28 | Copyright © 2011 __MyCompanyName__. All rights reserved. 29 | NSMainNibFile 30 | MainMenu 31 | NSPrincipalClass 32 | NSApplication 33 | 34 | 35 | -------------------------------------------------------------------------------- /Examples/GCD/UdpEchoClient/Desktop/UdpEchoClient/UdpEchoClient-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'UdpEchoClient' target in the 'UdpEchoClient' project 3 | // 4 | 5 | #ifdef __OBJC__ 6 | #import 7 | #endif 8 | -------------------------------------------------------------------------------- /Examples/GCD/UdpEchoClient/Desktop/UdpEchoClient/en.lproj/Credits.rtf: -------------------------------------------------------------------------------- 1 | {\rtf0\ansi{\fonttbl\f0\fswiss Helvetica;} 2 | {\colortbl;\red255\green255\blue255;} 3 | \paperw9840\paperh8400 4 | \pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural 5 | 6 | \f0\b\fs24 \cf0 Engineering: 7 | \b0 \ 8 | Some people\ 9 | \ 10 | 11 | \b Human Interface Design: 12 | \b0 \ 13 | Some other people\ 14 | \ 15 | 16 | \b Testing: 17 | \b0 \ 18 | Hopefully not nobody\ 19 | \ 20 | 21 | \b Documentation: 22 | \b0 \ 23 | Whoever\ 24 | \ 25 | 26 | \b With special thanks to: 27 | \b0 \ 28 | Mom\ 29 | } 30 | -------------------------------------------------------------------------------- /Examples/GCD/UdpEchoClient/Desktop/UdpEchoClient/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /Examples/GCD/UdpEchoClient/Desktop/UdpEchoClient/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // UdpEchoClient 4 | // 5 | // Created by Robbie Hanson on 11/28/11. 6 | // Copyright (c) 2011 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | int main(int argc, char *argv[]) 12 | { 13 | return NSApplicationMain(argc, (const char **)argv); 14 | } 15 | -------------------------------------------------------------------------------- /Examples/GCD/UdpEchoClient/Mobile/Default-568h@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/52im/CocoaAsyncSocket/562bae6af6dbd7e1891293dae20b9f79a2fd7228/Examples/GCD/UdpEchoClient/Mobile/Default-568h@2x.png -------------------------------------------------------------------------------- /Examples/GCD/UdpEchoClient/Mobile/UdpEchoClient.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Examples/GCD/UdpEchoClient/Mobile/UdpEchoClient/AppDelegate.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | @class ViewController; 4 | 5 | 6 | @interface AppDelegate : UIResponder 7 | 8 | @property (strong, nonatomic) UIWindow *window; 9 | @property (strong, nonatomic) ViewController *viewController; 10 | 11 | @end 12 | -------------------------------------------------------------------------------- /Examples/GCD/UdpEchoClient/Mobile/UdpEchoClient/AppDelegate.m: -------------------------------------------------------------------------------- 1 | #import "AppDelegate.h" 2 | #import "ViewController.h" 3 | #import "DDLog.h" 4 | #import "DDTTYLogger.h" 5 | 6 | // Log levels: off, error, warn, info, verbose 7 | static const int ddLogLevel = LOG_LEVEL_VERBOSE; 8 | 9 | 10 | @implementation AppDelegate 11 | 12 | @synthesize window = _window; 13 | @synthesize viewController = _viewController; 14 | 15 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 16 | { 17 | // Setup our logging framework. 18 | [DDLog addLogger:[DDTTYLogger sharedInstance]]; 19 | 20 | self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 21 | 22 | self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil]; 23 | self.window.rootViewController = self.viewController; 24 | 25 | [self.window makeKeyAndVisible]; 26 | return YES; 27 | } 28 | 29 | - (void)applicationWillResignActive:(UIApplication *)application 30 | { 31 | } 32 | 33 | - (void)applicationDidEnterBackground:(UIApplication *)application 34 | { 35 | } 36 | 37 | - (void)applicationWillEnterForeground:(UIApplication *)application 38 | { 39 | } 40 | 41 | - (void)applicationDidBecomeActive:(UIApplication *)application 42 | { 43 | } 44 | 45 | - (void)applicationWillTerminate:(UIApplication *)application 46 | { 47 | } 48 | 49 | @end 50 | -------------------------------------------------------------------------------- /Examples/GCD/UdpEchoClient/Mobile/UdpEchoClient/UdpEchoClient-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDisplayName 8 | ${PRODUCT_NAME} 9 | CFBundleExecutable 10 | ${EXECUTABLE_NAME} 11 | CFBundleIdentifier 12 | com.deusty.${PRODUCT_NAME:rfc1034identifier} 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1.0 25 | LSRequiresIPhoneOS 26 | 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /Examples/GCD/UdpEchoClient/Mobile/UdpEchoClient/UdpEchoClient-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'UdpEchoClient' target in the 'UdpEchoClient' project 3 | // 4 | 5 | #import 6 | 7 | #ifndef __IPHONE_4_0 8 | #warning "This project uses features only available in iOS SDK 4.0 and later." 9 | #endif 10 | 11 | #ifdef __OBJC__ 12 | #import 13 | #import 14 | #endif 15 | -------------------------------------------------------------------------------- /Examples/GCD/UdpEchoClient/Mobile/UdpEchoClient/ViewController.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import "GCDAsyncUdpSocket.h" 3 | 4 | @interface ViewController : UIViewController 5 | { 6 | IBOutlet UITextField *addrField; 7 | IBOutlet UITextField *portField; 8 | IBOutlet UITextField *messageField; 9 | IBOutlet UIWebView *webView; 10 | } 11 | 12 | - (IBAction)send:(id)sender; 13 | 14 | @end 15 | -------------------------------------------------------------------------------- /Examples/GCD/UdpEchoClient/Mobile/UdpEchoClient/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /Examples/GCD/UdpEchoClient/Mobile/UdpEchoClient/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // UdpEchoClient 4 | // 5 | // Created by Robbie Hanson on 4/5/12. 6 | // Copyright (c) 2012 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "AppDelegate.h" 12 | 13 | int main(int argc, char *argv[]) 14 | { 15 | @autoreleasepool { 16 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Examples/GCD/UdpEchoServer/Desktop/UdpEchoServer.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Examples/GCD/UdpEchoServer/Desktop/UdpEchoServer/AppDelegate.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import "GCDAsyncUdpSocket.h" 3 | 4 | 5 | @interface AppDelegate : NSObject 6 | { 7 | GCDAsyncUdpSocket *udpSocket; 8 | BOOL isRunning; 9 | } 10 | 11 | @property (unsafe_unretained) IBOutlet NSWindow *window; 12 | @property IBOutlet NSTextField *portField; 13 | @property IBOutlet NSButton *startStopButton; 14 | @property IBOutlet NSTextView *logView; 15 | 16 | - (IBAction)startStopButtonPressed:(id)sender; 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /Examples/GCD/UdpEchoServer/Desktop/UdpEchoServer/AppDelegate.m: -------------------------------------------------------------------------------- 1 | #import "AppDelegate.h" 2 | #import "DDLog.h" 3 | #import "DDTTYLogger.h" 4 | 5 | // Log levels: off, error, warn, info, verbose 6 | static const int ddLogLevel = LOG_LEVEL_VERBOSE; 7 | 8 | #define FORMAT(format, ...) [NSString stringWithFormat:(format), ##__VA_ARGS__] 9 | 10 | 11 | @implementation AppDelegate 12 | 13 | @synthesize window = _window; 14 | @synthesize portField; 15 | @synthesize startStopButton; 16 | @synthesize logView; 17 | 18 | - (void)applicationDidFinishLaunching:(NSNotification *)aNotification 19 | { 20 | // Setup our logging framework. 21 | 22 | [DDLog addLogger:[DDTTYLogger sharedInstance]]; 23 | 24 | // Setup our socket. 25 | // The socket will invoke our delegate methods using the usual delegate paradigm. 26 | // However, it will invoke the delegate methods on a specified GCD delegate dispatch queue. 27 | // 28 | // Now we can configure the delegate dispatch queues however we want. 29 | // We could simply use the main dispatch queue, so the delegate methods are invoked on the main thread. 30 | // Or we could use a dedicated dispatch queue, which could be helpful if we were doing a lot of processing. 31 | // 32 | // The best approach for your application will depend upon convenience, requirements and performance. 33 | // 34 | // For this simple example, we're just going to use the main thread. 35 | 36 | udpSocket = [[GCDAsyncUdpSocket alloc] initWithDelegate:self delegateQueue:dispatch_get_main_queue()]; 37 | } 38 | 39 | - (void)awakeFromNib 40 | { 41 | [logView setEnabledTextCheckingTypes:0]; 42 | [logView setAutomaticSpellingCorrectionEnabled:NO]; 43 | } 44 | 45 | - (void)scrollToBottom 46 | { 47 | NSScrollView *scrollView = [logView enclosingScrollView]; 48 | NSPoint newScrollOrigin; 49 | 50 | if ([[scrollView documentView] isFlipped]) 51 | newScrollOrigin = NSMakePoint(0.0F, NSMaxY([[scrollView documentView] frame])); 52 | else 53 | newScrollOrigin = NSMakePoint(0.0F, 0.0F); 54 | 55 | [[scrollView documentView] scrollPoint:newScrollOrigin]; 56 | } 57 | 58 | - (void)logError:(NSString *)msg 59 | { 60 | NSString *paragraph = [NSString stringWithFormat:@"%@\n", msg]; 61 | 62 | NSMutableDictionary *attributes = [NSMutableDictionary dictionaryWithCapacity:1]; 63 | [attributes setObject:[NSColor redColor] forKey:NSForegroundColorAttributeName]; 64 | 65 | NSAttributedString *as = [[NSAttributedString alloc] initWithString:paragraph attributes:attributes]; 66 | 67 | [[logView textStorage] appendAttributedString:as]; 68 | [self scrollToBottom]; 69 | } 70 | 71 | - (void)logInfo:(NSString *)msg 72 | { 73 | NSString *paragraph = [NSString stringWithFormat:@"%@\n", msg]; 74 | 75 | NSMutableDictionary *attributes = [NSMutableDictionary dictionaryWithCapacity:1]; 76 | [attributes setObject:[NSColor purpleColor] forKey:NSForegroundColorAttributeName]; 77 | 78 | NSAttributedString *as = [[NSAttributedString alloc] initWithString:paragraph attributes:attributes]; 79 | 80 | [[logView textStorage] appendAttributedString:as]; 81 | [self scrollToBottom]; 82 | } 83 | 84 | - (void)logMessage:(NSString *)msg 85 | { 86 | NSString *paragraph = [NSString stringWithFormat:@"%@\n", msg]; 87 | 88 | NSMutableDictionary *attributes = [NSMutableDictionary dictionaryWithCapacity:1]; 89 | [attributes setObject:[NSColor blackColor] forKey:NSForegroundColorAttributeName]; 90 | 91 | NSAttributedString *as = [[NSAttributedString alloc] initWithString:paragraph attributes:attributes]; 92 | 93 | [[logView textStorage] appendAttributedString:as]; 94 | [self scrollToBottom]; 95 | } 96 | 97 | - (IBAction)startStopButtonPressed:(id)sender 98 | { 99 | if (isRunning) 100 | { 101 | // STOP udp echo server 102 | 103 | [udpSocket close]; 104 | 105 | [self logInfo:@"Stopped Udp Echo server"]; 106 | isRunning = false; 107 | 108 | [portField setEnabled:YES]; 109 | [startStopButton setTitle:@"Start"]; 110 | } 111 | else 112 | { 113 | // START udp echo server 114 | 115 | int port = [portField intValue]; 116 | if (port < 0 || port > 65535) 117 | { 118 | [portField setStringValue:@""]; 119 | port = 0; 120 | } 121 | 122 | NSError *error = nil; 123 | 124 | if (![udpSocket bindToPort:port error:&error]) 125 | { 126 | [self logError:FORMAT(@"Error starting server (bind): %@", error)]; 127 | return; 128 | } 129 | if (![udpSocket beginReceiving:&error]) 130 | { 131 | [udpSocket close]; 132 | 133 | [self logError:FORMAT(@"Error starting server (recv): %@", error)]; 134 | return; 135 | } 136 | 137 | [self logInfo:FORMAT(@"Udp Echo server started on port %hu", [udpSocket localPort])]; 138 | isRunning = YES; 139 | 140 | [portField setEnabled:NO]; 141 | [startStopButton setTitle:@"Stop"]; 142 | } 143 | } 144 | 145 | - (void)udpSocket:(GCDAsyncUdpSocket *)sock didReceiveData:(NSData *)data 146 | fromAddress:(NSData *)address 147 | withFilterContext:(id)filterContext 148 | { 149 | NSString *msg = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; 150 | if (msg) 151 | { 152 | [self logMessage:msg]; 153 | } 154 | else 155 | { 156 | [self logError:@"Error converting received data into UTF-8 String"]; 157 | } 158 | 159 | [udpSocket sendData:data toAddress:address withTimeout:-1 tag:0]; 160 | } 161 | 162 | @end 163 | -------------------------------------------------------------------------------- /Examples/GCD/UdpEchoServer/Desktop/UdpEchoServer/UdpEchoServer-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIconFile 10 | 11 | CFBundleIdentifier 12 | com.deusty.oss.${PRODUCT_NAME:rfc1034identifier} 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1 25 | LSMinimumSystemVersion 26 | ${MACOSX_DEPLOYMENT_TARGET} 27 | NSHumanReadableCopyright 28 | Copyright © 2011 __MyCompanyName__. All rights reserved. 29 | NSMainNibFile 30 | MainMenu 31 | NSPrincipalClass 32 | NSApplication 33 | 34 | 35 | -------------------------------------------------------------------------------- /Examples/GCD/UdpEchoServer/Desktop/UdpEchoServer/UdpEchoServer-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'UdpEchoServer' target in the 'UdpEchoServer' project 3 | // 4 | 5 | #ifdef __OBJC__ 6 | #import 7 | #endif 8 | -------------------------------------------------------------------------------- /Examples/GCD/UdpEchoServer/Desktop/UdpEchoServer/en.lproj/Credits.rtf: -------------------------------------------------------------------------------- 1 | {\rtf0\ansi{\fonttbl\f0\fswiss Helvetica;} 2 | {\colortbl;\red255\green255\blue255;} 3 | \paperw9840\paperh8400 4 | \pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural 5 | 6 | \f0\b\fs24 \cf0 Engineering: 7 | \b0 \ 8 | Some people\ 9 | \ 10 | 11 | \b Human Interface Design: 12 | \b0 \ 13 | Some other people\ 14 | \ 15 | 16 | \b Testing: 17 | \b0 \ 18 | Hopefully not nobody\ 19 | \ 20 | 21 | \b Documentation: 22 | \b0 \ 23 | Whoever\ 24 | \ 25 | 26 | \b With special thanks to: 27 | \b0 \ 28 | Mom\ 29 | } 30 | -------------------------------------------------------------------------------- /Examples/GCD/UdpEchoServer/Desktop/UdpEchoServer/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /Examples/GCD/UdpEchoServer/Desktop/UdpEchoServer/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // UdpEchoServer 4 | // 5 | // Created by Robbie Hanson on 11/23/11. 6 | // Copyright (c) 2011 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | int main(int argc, char *argv[]) 12 | { 13 | return NSApplicationMain(argc, (const char **)argv); 14 | } 15 | -------------------------------------------------------------------------------- /Examples/GCD/UdpEchoServer/Mobile/UdpEchoServer.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Examples/GCD/UdpEchoServer/Mobile/UdpEchoServer/AppDelegate.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | @class ViewController; 4 | 5 | 6 | @interface AppDelegate : UIResponder 7 | 8 | @property (strong, nonatomic) UIWindow *window; 9 | @property (strong, nonatomic) ViewController *viewController; 10 | 11 | @end 12 | -------------------------------------------------------------------------------- /Examples/GCD/UdpEchoServer/Mobile/UdpEchoServer/AppDelegate.m: -------------------------------------------------------------------------------- 1 | #import "AppDelegate.h" 2 | #import "ViewController.h" 3 | #import "DDLog.h" 4 | #import "DDTTYLogger.h" 5 | 6 | // Log levels: off, error, warn, info, verbose 7 | static const int ddLogLevel = LOG_LEVEL_VERBOSE; 8 | 9 | 10 | @implementation AppDelegate 11 | 12 | @synthesize window = _window; 13 | @synthesize viewController = _viewController; 14 | 15 | 16 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 17 | { 18 | // Setup our logging framework. 19 | 20 | [DDLog addLogger:[DDTTYLogger sharedInstance]]; 21 | 22 | // Setup UI 23 | 24 | self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 25 | self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil]; 26 | self.window.rootViewController = self.viewController; 27 | [self.window makeKeyAndVisible]; 28 | return YES; 29 | } 30 | 31 | - (void)applicationWillResignActive:(UIApplication *)application 32 | { 33 | } 34 | 35 | - (void)applicationDidEnterBackground:(UIApplication *)application 36 | { 37 | } 38 | 39 | - (void)applicationWillEnterForeground:(UIApplication *)application 40 | { 41 | } 42 | 43 | - (void)applicationDidBecomeActive:(UIApplication *)application 44 | { 45 | } 46 | 47 | - (void)applicationWillTerminate:(UIApplication *)application 48 | { 49 | } 50 | 51 | @end 52 | -------------------------------------------------------------------------------- /Examples/GCD/UdpEchoServer/Mobile/UdpEchoServer/UdpEchoServer-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDisplayName 8 | ${PRODUCT_NAME} 9 | CFBundleExecutable 10 | ${EXECUTABLE_NAME} 11 | CFBundleIdentifier 12 | com.deusty.${PRODUCT_NAME:rfc1034identifier} 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1.0 25 | LSRequiresIPhoneOS 26 | 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /Examples/GCD/UdpEchoServer/Mobile/UdpEchoServer/UdpEchoServer-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'UdpEchoServer' target in the 'UdpEchoServer' project 3 | // 4 | 5 | #import 6 | 7 | #ifndef __IPHONE_4_0 8 | #warning "This project uses features only available in iOS SDK 4.0 and later." 9 | #endif 10 | 11 | #ifdef __OBJC__ 12 | #import 13 | #import 14 | #endif 15 | -------------------------------------------------------------------------------- /Examples/GCD/UdpEchoServer/Mobile/UdpEchoServer/ViewController.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import "GCDAsyncUdpSocket.h" 3 | 4 | @interface ViewController : UIViewController 5 | { 6 | IBOutlet UITextField *portField; 7 | IBOutlet UIButton *startStopButton; 8 | IBOutlet UIWebView *webView; 9 | } 10 | 11 | - (IBAction)startStop:(id)sender; 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /Examples/GCD/UdpEchoServer/Mobile/UdpEchoServer/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /Examples/GCD/UdpEchoServer/Mobile/UdpEchoServer/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // UdpEchoServer 4 | // 5 | // Created by Robbie Hanson on 4/8/12. 6 | // Copyright (c) 2012 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "AppDelegate.h" 12 | 13 | int main(int argc, char *argv[]) 14 | { 15 | @autoreleasepool { 16 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Examples/RunLoop/EchoServer/AppController.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | @class AsyncSocket; 4 | 5 | @interface AppController : NSObject 6 | { 7 | AsyncSocket *listenSocket; 8 | NSMutableArray *connectedSockets; 9 | 10 | BOOL isRunning; 11 | 12 | IBOutlet id logView; 13 | IBOutlet id portField; 14 | IBOutlet id startStopButton; 15 | } 16 | - (IBAction)startStop:(id)sender; 17 | @end 18 | -------------------------------------------------------------------------------- /Examples/RunLoop/EchoServer/EchoServer.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Examples/RunLoop/EchoServer/EchoServer_Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'EchoServer' target in the 'EchoServer' project 3 | // 4 | 5 | #ifdef __OBJC__ 6 | #import 7 | #endif 8 | -------------------------------------------------------------------------------- /Examples/RunLoop/EchoServer/English.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/52im/CocoaAsyncSocket/562bae6af6dbd7e1891293dae20b9f79a2fd7228/Examples/RunLoop/EchoServer/English.lproj/InfoPlist.strings -------------------------------------------------------------------------------- /Examples/RunLoop/EchoServer/English.lproj/MainMenu.nib/keyedobjects.nib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/52im/CocoaAsyncSocket/562bae6af6dbd7e1891293dae20b9f79a2fd7228/Examples/RunLoop/EchoServer/English.lproj/MainMenu.nib/keyedobjects.nib -------------------------------------------------------------------------------- /Examples/RunLoop/EchoServer/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIconFile 10 | 11 | CFBundleIdentifier 12 | com.yourcompany.EchoServer 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | APPL 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1.0 23 | NSMainNibFile 24 | MainMenu 25 | NSPrincipalClass 26 | NSApplication 27 | 28 | 29 | -------------------------------------------------------------------------------- /Examples/RunLoop/EchoServer/Instructions.txt: -------------------------------------------------------------------------------- 1 | First, build and run the EchoServer. 2 | You can set it to run on a specific port, or allow to pick an available port. 3 | Now start the echo server. It will output the port it started on. 4 | 5 | You can now use telnet to connect to the echo server and test it. 6 | Using the Terminal (/Applications/Utilities/Terminal.app) 7 | type in the following: 8 | telnet localhost [port] 9 | 10 | where "[port]" is replaced by the port the Echo server is running on. 11 | 12 | Type in anything you want, and hit return. 13 | Whatever you typed in will be displayed in the Echo Server, and echoed back to you. 14 | 15 | To end your telnet session hit Ctrl-], and type "quit". -------------------------------------------------------------------------------- /Examples/RunLoop/EchoServer/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // EchoServer 4 | // 5 | // Created by Robbie Hanson on 7/10/08. 6 | // Copyright __MyCompanyName__ 2008. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | int main(int argc, char *argv[]) 12 | { 13 | return NSApplicationMain(argc, (const char **) argv); 14 | } 15 | -------------------------------------------------------------------------------- /Examples/RunLoop/InterfaceTest/Classes/InterfaceTestAppDelegate.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | @class InterfaceTestViewController; 4 | @class AsyncSocket; 5 | 6 | 7 | @interface InterfaceTestAppDelegate : NSObject 8 | { 9 | CFHostRef host; 10 | AsyncSocket *asyncSocket; 11 | 12 | UIWindow *window; 13 | InterfaceTestViewController *viewController; 14 | } 15 | 16 | @property (nonatomic) IBOutlet UIWindow *window; 17 | @property (nonatomic) IBOutlet InterfaceTestViewController *viewController; 18 | 19 | @end 20 | 21 | -------------------------------------------------------------------------------- /Examples/RunLoop/InterfaceTest/Classes/InterfaceTestViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // InterfaceTestViewController.h 3 | // InterfaceTest 4 | // 5 | // Created by Robbie Hanson on 10/15/10. 6 | // Copyright 2010 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface InterfaceTestViewController : UIViewController { 12 | 13 | } 14 | 15 | @end 16 | 17 | -------------------------------------------------------------------------------- /Examples/RunLoop/InterfaceTest/Classes/InterfaceTestViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // InterfaceTestViewController.m 3 | // InterfaceTest 4 | // 5 | // Created by Robbie Hanson on 10/15/10. 6 | // Copyright 2010 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #import "InterfaceTestViewController.h" 10 | 11 | @implementation InterfaceTestViewController 12 | 13 | 14 | 15 | /* 16 | // The designated initializer. Override to perform setup that is required before the view is loaded. 17 | - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { 18 | if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) { 19 | // Custom initialization 20 | } 21 | return self; 22 | } 23 | */ 24 | 25 | /* 26 | // Implement loadView to create a view hierarchy programmatically, without using a nib. 27 | - (void)loadView { 28 | } 29 | */ 30 | 31 | 32 | /* 33 | // Implement viewDidLoad to do additional setup after loading the view, typically from a nib. 34 | - (void)viewDidLoad { 35 | [super viewDidLoad]; 36 | } 37 | */ 38 | 39 | 40 | /* 41 | // Override to allow orientations other than the default portrait orientation. 42 | - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 43 | // Return YES for supported orientations 44 | return (interfaceOrientation == UIInterfaceOrientationPortrait); 45 | } 46 | */ 47 | 48 | - (void)didReceiveMemoryWarning { 49 | // Releases the view if it doesn't have a superview. 50 | [super didReceiveMemoryWarning]; 51 | 52 | // Release any cached data, images, etc that aren't in use. 53 | } 54 | 55 | - (void)viewDidUnload { 56 | // Release any retained subviews of the main view. 57 | // e.g. self.myOutlet = nil; 58 | } 59 | 60 | 61 | 62 | @end 63 | -------------------------------------------------------------------------------- /Examples/RunLoop/InterfaceTest/Default-568h@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/52im/CocoaAsyncSocket/562bae6af6dbd7e1891293dae20b9f79a2fd7228/Examples/RunLoop/InterfaceTest/Default-568h@2x.png -------------------------------------------------------------------------------- /Examples/RunLoop/InterfaceTest/InterfaceTest-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleDisplayName 8 | ${PRODUCT_NAME} 9 | CFBundleExecutable 10 | ${EXECUTABLE_NAME} 11 | CFBundleIconFile 12 | 13 | CFBundleIdentifier 14 | com.yourcompany.${PRODUCT_NAME:rfc1034identifier} 15 | CFBundleInfoDictionaryVersion 16 | 6.0 17 | CFBundleName 18 | ${PRODUCT_NAME} 19 | CFBundlePackageType 20 | APPL 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1.0 25 | LSRequiresIPhoneOS 26 | 27 | NSMainNibFile 28 | MainWindow 29 | 30 | 31 | -------------------------------------------------------------------------------- /Examples/RunLoop/InterfaceTest/InterfaceTest.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Examples/RunLoop/InterfaceTest/InterfaceTest_Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'InterfaceTest' target in the 'InterfaceTest' project 3 | // 4 | 5 | #ifdef __OBJC__ 6 | #import 7 | #import 8 | #endif 9 | -------------------------------------------------------------------------------- /Examples/RunLoop/InterfaceTest/Readme.txt: -------------------------------------------------------------------------------- 1 | InterfaceTest is an iPhone project that demonstrates some of AsyncSocket's interface abilities. 2 | 3 | Most machines have multiple network interfaces. For example: 4 | - Ethernet 5 | - WiFi 6 | - 3G (cellular) 7 | - Bluetooth 8 | - Loopback (local machine only) 9 | 10 | Which leads to the question: 11 | If you are setting up sockets, which interface will your socket be running on? 12 | 13 | By default, if you don't specify an inteface, then the following rules generally apply: 14 | 15 | - Server sockets (listening/accepting) will accept incoming connections on any inteface. 16 | - Client sockets (connecting) will make outgoing connections on the primary interface. 17 | 18 | The primary interface on iPhone is WiFi. 19 | The primary interface on Mac is configurable via system preferences. 20 | 21 | But you can specify a particular interface using AsyncSocket. There are various examples of when one might want to do this. 22 | 23 | - You're trying to make a bluetooth connection. 24 | 25 | - Your iPhone app only supports WiFi, so you need to ensure your socket is only using the WiFi interface. 26 | 27 | - You want to create a local-only server socket on Mac for inter-process communication. You want to ensure only processes running on the local device can connect to your server. 28 | 29 | 30 | The IntefaceTest project demonstrates specifying a particular interface to use for an outgoing connection to google.com. You can force either the WiFi interface or the 3G/cellular interface. -------------------------------------------------------------------------------- /Examples/RunLoop/InterfaceTest/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // InterfaceTest 4 | // 5 | // Created by Robbie Hanson on 10/15/10. 6 | // Copyright 2010 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | int main(int argc, char *argv[]) { 12 | 13 | @autoreleasepool { 14 | int retVal = UIApplicationMain(argc, argv, nil, nil); 15 | return retVal; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Examples/RunLoop/UdpEchoClient/UdpEchoClient.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Examples/RunLoop/UdpEchoClient/UdpEchoClient/AppDelegate.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import "AsyncUdpSocket.h" 3 | 4 | 5 | @interface AppDelegate : NSObject 6 | { 7 | long tag; 8 | AsyncUdpSocket *udpSocket; 9 | } 10 | 11 | @property (assign) IBOutlet NSWindow *window; 12 | 13 | @property IBOutlet NSTextField * addrField; 14 | @property IBOutlet NSTextField * portField; 15 | @property IBOutlet NSTextField * messageField; 16 | @property IBOutlet NSButton * sendButton; 17 | @property IBOutlet NSTextView * logView; 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /Examples/RunLoop/UdpEchoClient/UdpEchoClient/AppDelegate.m: -------------------------------------------------------------------------------- 1 | #import "AppDelegate.h" 2 | 3 | #define FORMAT(format, ...) [NSString stringWithFormat:(format), ##__VA_ARGS__] 4 | 5 | 6 | @implementation AppDelegate 7 | 8 | @synthesize window = _window; 9 | @synthesize addrField; 10 | @synthesize portField; 11 | @synthesize messageField; 12 | @synthesize sendButton; 13 | @synthesize logView; 14 | 15 | - (void)applicationDidFinishLaunching:(NSNotification *)aNotification 16 | { 17 | udpSocket = [[AsyncUdpSocket alloc] initWithDelegate:self]; 18 | 19 | NSError *error = nil; 20 | 21 | if (![udpSocket bindToPort:0 error:&error]) 22 | { 23 | NSLog(@"Error binding: %@", error); 24 | return; 25 | } 26 | 27 | [udpSocket receiveWithTimeout:-1 tag:0]; 28 | 29 | NSLog(@"Ready"); 30 | } 31 | 32 | - (void)scrollToBottom 33 | { 34 | NSScrollView *scrollView = [logView enclosingScrollView]; 35 | NSPoint newScrollOrigin; 36 | 37 | if ([[scrollView documentView] isFlipped]) 38 | newScrollOrigin = NSMakePoint(0.0F, NSMaxY([[scrollView documentView] frame])); 39 | else 40 | newScrollOrigin = NSMakePoint(0.0F, 0.0F); 41 | 42 | [[scrollView documentView] scrollPoint:newScrollOrigin]; 43 | } 44 | 45 | - (void)logError:(NSString *)msg 46 | { 47 | NSString *paragraph = [NSString stringWithFormat:@"%@\n", msg]; 48 | 49 | NSMutableDictionary *attributes = [NSMutableDictionary dictionaryWithCapacity:1]; 50 | [attributes setObject:[NSColor redColor] forKey:NSForegroundColorAttributeName]; 51 | 52 | NSAttributedString *as = [[NSAttributedString alloc] initWithString:paragraph attributes:attributes]; 53 | 54 | [[logView textStorage] appendAttributedString:as]; 55 | [self scrollToBottom]; 56 | } 57 | 58 | - (void)logInfo:(NSString *)msg 59 | { 60 | NSString *paragraph = [NSString stringWithFormat:@"%@\n", msg]; 61 | 62 | NSMutableDictionary *attributes = [NSMutableDictionary dictionaryWithCapacity:1]; 63 | [attributes setObject:[NSColor purpleColor] forKey:NSForegroundColorAttributeName]; 64 | 65 | NSAttributedString *as = [[NSAttributedString alloc] initWithString:paragraph attributes:attributes]; 66 | 67 | [[logView textStorage] appendAttributedString:as]; 68 | [self scrollToBottom]; 69 | } 70 | 71 | - (void)logMessage:(NSString *)msg 72 | { 73 | NSString *paragraph = [NSString stringWithFormat:@"%@\n", msg]; 74 | 75 | NSMutableDictionary *attributes = [NSMutableDictionary dictionaryWithCapacity:1]; 76 | [attributes setObject:[NSColor blackColor] forKey:NSForegroundColorAttributeName]; 77 | 78 | NSAttributedString *as = [[NSAttributedString alloc] initWithString:paragraph attributes:attributes]; 79 | 80 | [[logView textStorage] appendAttributedString:as]; 81 | [self scrollToBottom]; 82 | } 83 | 84 | - (IBAction)send:(id)sender 85 | { 86 | NSString *host = [addrField stringValue]; 87 | if ([host length] == 0) 88 | { 89 | [self logError:@"Address required"]; 90 | return; 91 | } 92 | 93 | int port = [portField intValue]; 94 | if (port <= 0 || port > 65535) 95 | { 96 | [self logError:@"Valid port required"]; 97 | return; 98 | } 99 | 100 | NSString *msg = [messageField stringValue]; 101 | if ([msg length] == 0) 102 | { 103 | [self logError:@"Message required"]; 104 | return; 105 | } 106 | 107 | NSData *data = [msg dataUsingEncoding:NSUTF8StringEncoding]; 108 | [udpSocket sendData:data toHost:host port:port withTimeout:-1 tag:tag]; 109 | 110 | [self logMessage:FORMAT(@"SENT (%i): %@", (int)tag, msg)]; 111 | 112 | tag++; 113 | } 114 | 115 | - (void)onUdpSocket:(AsyncUdpSocket *)sock didSendDataWithTag:(long)tag 116 | { 117 | // You could add checks here 118 | } 119 | 120 | - (void)onUdpSocket:(AsyncUdpSocket *)sock didNotSendDataWithTag:(long)tag dueToError:(NSError *)error 121 | { 122 | // You could add checks here 123 | } 124 | 125 | - (BOOL)onUdpSocket:(AsyncUdpSocket *)sock 126 | didReceiveData:(NSData *)data 127 | withTag:(long)tag 128 | fromHost:(NSString *)host 129 | port:(UInt16)port 130 | { 131 | NSString *msg = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; 132 | if (msg) 133 | { 134 | [self logMessage:FORMAT(@"RECV: %@", msg)]; 135 | } 136 | else 137 | { 138 | [self logInfo:FORMAT(@"RECV: Unknown message from: %@:%hu", host, port)]; 139 | } 140 | 141 | [udpSocket receiveWithTimeout:-1 tag:0]; 142 | return YES; 143 | } 144 | 145 | @end 146 | -------------------------------------------------------------------------------- /Examples/RunLoop/UdpEchoClient/UdpEchoClient/UdpEchoClient-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIconFile 10 | 11 | CFBundleIdentifier 12 | com.deusty.${PRODUCT_NAME:rfc1034identifier} 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1 25 | LSMinimumSystemVersion 26 | ${MACOSX_DEPLOYMENT_TARGET} 27 | NSHumanReadableCopyright 28 | Copyright © 2012 __MyCompanyName__. All rights reserved. 29 | NSMainNibFile 30 | MainMenu 31 | NSPrincipalClass 32 | NSApplication 33 | 34 | 35 | -------------------------------------------------------------------------------- /Examples/RunLoop/UdpEchoClient/UdpEchoClient/UdpEchoClient-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'UdpEchoClient' target in the 'UdpEchoClient' project 3 | // 4 | 5 | #ifdef __OBJC__ 6 | #import 7 | #endif 8 | -------------------------------------------------------------------------------- /Examples/RunLoop/UdpEchoClient/UdpEchoClient/en.lproj/Credits.rtf: -------------------------------------------------------------------------------- 1 | {\rtf0\ansi{\fonttbl\f0\fswiss Helvetica;} 2 | {\colortbl;\red255\green255\blue255;} 3 | \paperw9840\paperh8400 4 | \pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural 5 | 6 | \f0\b\fs24 \cf0 Engineering: 7 | \b0 \ 8 | Some people\ 9 | \ 10 | 11 | \b Human Interface Design: 12 | \b0 \ 13 | Some other people\ 14 | \ 15 | 16 | \b Testing: 17 | \b0 \ 18 | Hopefully not nobody\ 19 | \ 20 | 21 | \b Documentation: 22 | \b0 \ 23 | Whoever\ 24 | \ 25 | 26 | \b With special thanks to: 27 | \b0 \ 28 | Mom\ 29 | } 30 | -------------------------------------------------------------------------------- /Examples/RunLoop/UdpEchoClient/UdpEchoClient/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /Examples/RunLoop/UdpEchoClient/UdpEchoClient/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // UdpEchoClient 4 | // 5 | // Created by Robbie Hanson on 4/1/12. 6 | // Copyright (c) 2012 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | int main(int argc, char *argv[]) 12 | { 13 | return NSApplicationMain(argc, (const char **)argv); 14 | } 15 | -------------------------------------------------------------------------------- /Examples/RunLoop/UdpEchoServer/UdpEchoServer.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Examples/RunLoop/UdpEchoServer/UdpEchoServer/AppDelegate.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import "AsyncUdpSocket.h" 3 | 4 | 5 | @interface AppDelegate : NSObject 6 | { 7 | AsyncUdpSocket *udpSocket; 8 | BOOL isRunning; 9 | } 10 | 11 | @property (unsafe_unretained) IBOutlet NSWindow *window; 12 | 13 | @property IBOutlet NSTextField *portField; 14 | @property IBOutlet NSButton *startStopButton; 15 | @property IBOutlet NSTextView *logView; 16 | 17 | - (IBAction)startStopButtonPressed:(id)sender; 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /Examples/RunLoop/UdpEchoServer/UdpEchoServer/AppDelegate.m: -------------------------------------------------------------------------------- 1 | #import "AppDelegate.h" 2 | 3 | #define FORMAT(format, ...) [NSString stringWithFormat:(format), ##__VA_ARGS__] 4 | 5 | 6 | @implementation AppDelegate 7 | 8 | @synthesize window = _window; 9 | @synthesize portField; 10 | @synthesize startStopButton; 11 | @synthesize logView; 12 | 13 | - (void)applicationDidFinishLaunching:(NSNotification *)aNotification 14 | { 15 | udpSocket = [[AsyncUdpSocket alloc] initWithDelegate:self]; 16 | } 17 | 18 | - (void)awakeFromNib 19 | { 20 | [logView setEnabledTextCheckingTypes:0]; 21 | [logView setAutomaticSpellingCorrectionEnabled:NO]; 22 | } 23 | 24 | - (void)scrollToBottom 25 | { 26 | NSScrollView *scrollView = [logView enclosingScrollView]; 27 | NSPoint newScrollOrigin; 28 | 29 | if ([[scrollView documentView] isFlipped]) 30 | newScrollOrigin = NSMakePoint(0.0F, NSMaxY([[scrollView documentView] frame])); 31 | else 32 | newScrollOrigin = NSMakePoint(0.0F, 0.0F); 33 | 34 | [[scrollView documentView] scrollPoint:newScrollOrigin]; 35 | } 36 | 37 | - (void)logError:(NSString *)msg 38 | { 39 | NSString *paragraph = [NSString stringWithFormat:@"%@\n", msg]; 40 | 41 | NSMutableDictionary *attributes = [NSMutableDictionary dictionaryWithCapacity:1]; 42 | [attributes setObject:[NSColor redColor] forKey:NSForegroundColorAttributeName]; 43 | 44 | NSAttributedString *as = [[NSAttributedString alloc] initWithString:paragraph attributes:attributes]; 45 | 46 | [[logView textStorage] appendAttributedString:as]; 47 | [self scrollToBottom]; 48 | } 49 | 50 | - (void)logInfo:(NSString *)msg 51 | { 52 | NSString *paragraph = [NSString stringWithFormat:@"%@\n", msg]; 53 | 54 | NSMutableDictionary *attributes = [NSMutableDictionary dictionaryWithCapacity:1]; 55 | [attributes setObject:[NSColor purpleColor] forKey:NSForegroundColorAttributeName]; 56 | 57 | NSAttributedString *as = [[NSAttributedString alloc] initWithString:paragraph attributes:attributes]; 58 | 59 | [[logView textStorage] appendAttributedString:as]; 60 | [self scrollToBottom]; 61 | } 62 | 63 | - (void)logMessage:(NSString *)msg 64 | { 65 | NSString *paragraph = [NSString stringWithFormat:@"%@\n", msg]; 66 | 67 | NSMutableDictionary *attributes = [NSMutableDictionary dictionaryWithCapacity:1]; 68 | [attributes setObject:[NSColor blackColor] forKey:NSForegroundColorAttributeName]; 69 | 70 | NSAttributedString *as = [[NSAttributedString alloc] initWithString:paragraph attributes:attributes]; 71 | 72 | [[logView textStorage] appendAttributedString:as]; 73 | [self scrollToBottom]; 74 | } 75 | 76 | - (IBAction)startStopButtonPressed:(id)sender 77 | { 78 | if (isRunning) 79 | { 80 | // STOP udp echo server 81 | 82 | [udpSocket close]; 83 | 84 | [self logInfo:@"Stopped Udp Echo server"]; 85 | isRunning = false; 86 | 87 | [portField setEnabled:YES]; 88 | [startStopButton setTitle:@"Start"]; 89 | } 90 | else 91 | { 92 | // START udp echo server 93 | 94 | int port = [portField intValue]; 95 | if (port < 0 || port > 65535) 96 | { 97 | [portField setStringValue:@""]; 98 | port = 0; 99 | } 100 | 101 | NSError *error = nil; 102 | 103 | if (![udpSocket bindToPort:port error:&error]) 104 | { 105 | [self logError:FORMAT(@"Error starting server (bind): %@", error)]; 106 | return; 107 | } 108 | 109 | [udpSocket receiveWithTimeout:-1 tag:0]; 110 | 111 | [self logInfo:FORMAT(@"Udp Echo server started on port %hu", [udpSocket localPort])]; 112 | isRunning = YES; 113 | 114 | [portField setEnabled:NO]; 115 | [startStopButton setTitle:@"Stop"]; 116 | } 117 | } 118 | 119 | - (BOOL)onUdpSocket:(AsyncUdpSocket *)sock 120 | didReceiveData:(NSData *)data 121 | withTag:(long)tag 122 | fromHost:(NSString *)host 123 | port:(UInt16)port 124 | { 125 | NSString *msg = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; 126 | if (msg) 127 | { 128 | [self logMessage:msg]; 129 | } 130 | else 131 | { 132 | [self logError:@"Error converting received data into UTF-8 String"]; 133 | } 134 | 135 | [udpSocket sendData:data toHost:host port:port withTimeout:-1 tag:0]; 136 | [udpSocket receiveWithTimeout:-1 tag:0]; 137 | 138 | return YES; 139 | } 140 | 141 | @end 142 | -------------------------------------------------------------------------------- /Examples/RunLoop/UdpEchoServer/UdpEchoServer/UdpEchoServer-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIconFile 10 | 11 | CFBundleIdentifier 12 | com.deusty.${PRODUCT_NAME:rfc1034identifier} 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1 25 | LSMinimumSystemVersion 26 | ${MACOSX_DEPLOYMENT_TARGET} 27 | NSHumanReadableCopyright 28 | Copyright © 2012 __MyCompanyName__. All rights reserved. 29 | NSMainNibFile 30 | MainMenu 31 | NSPrincipalClass 32 | NSApplication 33 | 34 | 35 | -------------------------------------------------------------------------------- /Examples/RunLoop/UdpEchoServer/UdpEchoServer/UdpEchoServer-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'UdpEchoServer' target in the 'UdpEchoServer' project 3 | // 4 | 5 | #ifdef __OBJC__ 6 | #import 7 | #endif 8 | -------------------------------------------------------------------------------- /Examples/RunLoop/UdpEchoServer/UdpEchoServer/en.lproj/Credits.rtf: -------------------------------------------------------------------------------- 1 | {\rtf0\ansi{\fonttbl\f0\fswiss Helvetica;} 2 | {\colortbl;\red255\green255\blue255;} 3 | \paperw9840\paperh8400 4 | \pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural 5 | 6 | \f0\b\fs24 \cf0 Engineering: 7 | \b0 \ 8 | Some people\ 9 | \ 10 | 11 | \b Human Interface Design: 12 | \b0 \ 13 | Some other people\ 14 | \ 15 | 16 | \b Testing: 17 | \b0 \ 18 | Hopefully not nobody\ 19 | \ 20 | 21 | \b Documentation: 22 | \b0 \ 23 | Whoever\ 24 | \ 25 | 26 | \b With special thanks to: 27 | \b0 \ 28 | Mom\ 29 | } 30 | -------------------------------------------------------------------------------- /Examples/RunLoop/UdpEchoServer/UdpEchoServer/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /Examples/RunLoop/UdpEchoServer/UdpEchoServer/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // UdpEchoServer 4 | // 5 | // Created by Robbie Hanson on 4/1/12. 6 | // Copyright (c) 2012 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | int main(int argc, char *argv[]) 12 | { 13 | return NSApplicationMain(argc, (const char **)argv); 14 | } 15 | -------------------------------------------------------------------------------- /README.markdown: -------------------------------------------------------------------------------- 1 | # CocoaAsyncSocket 2 | [![Build Status](https://travis-ci.org/robbiehanson/CocoaAsyncSocket.svg?branch=master)](https://travis-ci.org/robbiehanson/CocoaAsyncSocket) [![Version Status](https://img.shields.io/cocoapods/v/CocoaAsyncSocket.svg?style=flat)](http://cocoadocs.org/docsets/CocoaAsyncSocket) [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) [![Platform](http://img.shields.io/cocoapods/p/CocoaAsyncSocket.svg?style=flat)](http://cocoapods.org/?q=CocoaAsyncSocket) [![license Public Domain](https://img.shields.io/badge/license-Public%20Domain-orange.svg?style=flat)](https://en.wikipedia.org/wiki/Public_domain) 3 | 4 | 5 | CocoaAsyncSocket provides easy-to-use and powerful asynchronous socket libraries for Mac and iOS. The classes are described below. 6 | 7 | ## Installation 8 | 9 | #### CocoaPods 10 | 11 | Install using [CocoaPods](http://cocoapods.org) by adding this line to your Podfile: 12 | 13 | ````ruby 14 | use_frameworks! # Add this if you are targeting iOS 8+ or using Swift 15 | pod 'CocoaAsyncSocket' 16 | ```` 17 | 18 | #### Carthage 19 | 20 | CocoaAsyncSocket is [Carthage](https://github.com/Carthage/Carthage) compatible. To include it add the following line to your `Cartfile` 21 | 22 | ```bash 23 | github "robbiehanson/CocoaAsyncSocket" "master" 24 | ``` 25 | 26 | The project is currently configured to build for **iOS**, **tvOS** and **Mac**. After building with carthage the resultant frameworks will be stored in: 27 | 28 | * `Carthage/Build/iOS/CocoaAsyncSocket.framework` 29 | * `Carthage/Build/tvOS/CocoaAsyncSocket.framework` 30 | * `Carthage/Build/Mac/CocoaAsyncSocket.framework` 31 | 32 | Select the correct framework(s) and drag it into your project. 33 | 34 | #### Manual 35 | 36 | You can also include it into your project by adding the source files directly, but you should probably be using a dependency manager to keep up to date. 37 | 38 | ### Importing 39 | 40 | Using Objective-C: 41 | 42 | ```obj-c 43 | // When using iOS 8+ frameworks 44 | @import CocoaAsyncSocket; 45 | 46 | // OR when not using frameworks, targeting iOS 7 or below 47 | #import "GCDAsyncSocket.h" // for TCP 48 | #import "GCDAsyncUdpSocket.h" // for UDP 49 | ``` 50 | 51 | Using Swift: 52 | 53 | ```swift 54 | import CocoaAsyncSocket 55 | ``` 56 | 57 | ## TCP 58 | 59 | **GCDAsyncSocket** and **AsyncSocket** are TCP/IP socket networking libraries. Here are the key features available in both: 60 | 61 | - Native objective-c, fully self-contained in one class.
62 | _No need to muck around with sockets or streams. This class handles everything for you._ 63 | 64 | - Full delegate support
65 | _Errors, connections, read completions, write completions, progress, and disconnections all result in a call to your delegate method._ 66 | 67 | - Queued non-blocking reads and writes, with optional timeouts.
68 | _You tell it what to read or write, and it handles everything for you. Queueing, buffering, and searching for termination sequences within the stream - all handled for you automatically._ 69 | 70 | - Automatic socket acceptance.
71 | _Spin up a server socket, tell it to accept connections, and it will call you with new instances of itself for each connection._ 72 | 73 | - Support for TCP streams over IPv4 and IPv6.
74 | _Automatically connect to IPv4 or IPv6 hosts. Automatically accept incoming connections over both IPv4 and IPv6 with a single instance of this class. No more worrying about multiple sockets._ 75 | 76 | - Support for TLS / SSL
77 | _Secure your socket with ease using just a single method call. Available for both client and server sockets._ 78 | 79 | **GCDAsyncSocket** is built atop Grand Central Dispatch: 80 | 81 | - Fully GCD based and Thread-Safe
82 | _It runs entirely within its own GCD dispatch_queue, and is completely thread-safe. Further, the delegate methods are all invoked asynchronously onto a dispatch_queue of your choosing. This means parallel operation of your socket code, and your delegate/processing code._ 83 | 84 | - The Latest Technology & Performance Optimizations
85 | _Internally the library takes advantage of technologies such as [kqueue's](http://en.wikipedia.org/wiki/Kqueue) to limit [system calls](http://en.wikipedia.org/wiki/System_call) and optimize buffer allocations. In other words, peak performance._ 86 | 87 | **AsyncSocket** wraps CFSocket and CFStream: 88 | 89 | - Fully Run-loop based
90 | _Use it on the main thread or a worker thread. It plugs into the NSRunLoop with configurable modes._ 91 | 92 | ## UDP 93 | 94 | **GCDAsyncUdpSocket** and **AsyncUdpSocket** are UDP/IP socket networking libraries. Here are the key features available in both: 95 | 96 | - Native objective-c, fully self-contained in one class.
97 | _No need to muck around with low-level sockets. This class handles everything for you._ 98 | 99 | - Full delegate support.
100 | _Errors, send completions, receive completions, and disconnections all result in a call to your delegate method._ 101 | 102 | - Queued non-blocking send and receive operations, with optional timeouts.
103 | _You tell it what to send or receive, and it handles everything for you. Queueing, buffering, waiting and checking errno - all handled for you automatically._ 104 | 105 | - Support for IPv4 and IPv6.
106 | _Automatically send/recv using IPv4 and/or IPv6. No more worrying about multiple sockets._ 107 | 108 | **GCDAsyncUdpSocket** is built atop Grand Central Dispatch: 109 | 110 | - Fully GCD based and Thread-Safe
111 | _It runs entirely within its own GCD dispatch_queue, and is completely thread-safe. Further, the delegate methods are all invoked asynchronously onto a dispatch_queue of your choosing. This means parallel operation of your socket code, and your delegate/processing code._ 112 | 113 | **AsyncUdpSocket** wraps CFSocket: 114 | 115 | - Fully Run-loop based
116 | _Use it on the main thread or a worker thread. It plugs into the NSRunLoop with configurable modes._ 117 | 118 | *** 119 | 120 | Can't find the answer to your question in any of the [wiki](https://github.com/robbiehanson/CocoaAsyncSocket/wiki) articles? Try the **[mailing list](http://groups.google.com/group/cocoaasyncsocket)**. 121 |
122 |
123 | Love the project? Wanna buy me a coffee? (or a beer :D) [![donation](http://www.paypal.com/en_US/i/btn/btn_donate_SM.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=2M8C699FQ8AW2) 124 | 125 | -------------------------------------------------------------------------------- /Source/CocoaAsyncSocket.h: -------------------------------------------------------------------------------- 1 | // 2 | // CocoaAsyncSocket.h 3 | // CocoaAsyncSocket 4 | // 5 | // Created by Derek Clarkson on 10/08/2015. 6 | // Copyright © 2015 Robbie Hanson. All rights reserved. 7 | // 8 | 9 | @import Foundation; 10 | 11 | //! Project version number for CocoaAsyncSocket. 12 | FOUNDATION_EXPORT double cocoaAsyncSocketVersionNumber; 13 | 14 | //! Project version string for CocoaAsyncSocket. 15 | FOUNDATION_EXPORT const unsigned char cocoaAsyncSocketVersionString[]; 16 | 17 | #import 18 | #import 19 | #import 20 | #import 21 | -------------------------------------------------------------------------------- /Source/GCD/Documentation.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |

Welcome to the CocoaAsyncSocket project!

5 | 6 |

7 | A wealth of documentation can be found on the Google Code homepage:
8 | https://github.com/robbiehanson/CocoaAsyncSocket 9 |

10 | 11 |

12 | If you are new to networking, it is recommended you start by reading the Intro page:
13 | https://github.com/robbiehanson/CocoaAsyncSocket/wiki/Intro 14 |

15 | 16 |

17 | If you are a seasoned networking professional, with 10+ years of experience writing low-level socket code, 18 | and detailed knowledge of the underlying BSD networking stack, then you can skip the CommonPitfalls page.
19 | Otherwise, it should be considered mandatory reading:
20 | https://github.com/robbiehanson/CocoaAsyncSocket/wiki/CommonPitfalls 21 |

22 | 23 |

24 | A little bit of investment in your knowledge and understanding of networking fundamentals can go a long way.
25 | And it can save you a LOT of time and frustration in the long run. 26 |

27 | 28 |

29 | Your first goto for reference should ALWAYS be the header files. They are extremely well documented. Please read them. 30 |

31 | 32 |

33 | Did I mention you should read the headers? They're docemented very nicely, in plain english. 34 |

35 | 36 |

37 | If you have any questions you are welcome to post to the CocoaAsyncSocket mailing list:
38 | http://groups.google.com/group/cocoaasyncsocket
39 |
40 | The list is archived, and available for browsing online.
41 | You may be able to instantly find the answer you're looking for with a quick search.
42 |

43 | 44 |

We hope the CocoaAsyncSocket project can provide you with powerful and easy to use networking libraries.

45 | 46 | 47 | -------------------------------------------------------------------------------- /Source/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | $(CURRENT_PROJECT_VERSION) 23 | NSPrincipalClass 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /Source/RunLoop/Documentation.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |

Welcome to the CocoaAsyncSocket project!

5 | 6 |

7 | A wealth of documentation can be found on the Google Code homepage:
8 | https://github.com/robbiehanson/CocoaAsyncSocket 9 |

10 | 11 |

12 | If you are new to networking, it is recommended you start by reading the Intro page:
13 | https://github.com/robbiehanson/CocoaAsyncSocket/wiki/Intro 14 |

15 | 16 |

17 | If you are a seasoned networking professional, with 10+ years of experience writing low-level socket code, 18 | and detailed knowledge of the underlying BSD networking stack, then you can skip the CommonPitfalls page.
19 | Otherwise, it should be considered mandatory reading:
20 | https://github.com/robbiehanson/CocoaAsyncSocket/wiki/CommonPitfalls 21 |

22 | 23 |

24 | A little bit of investment in your knowledge and understanding of networking fundamentals can go a long way.
25 | And it can save you a LOT of time and frustration in the long run. 26 |

27 | 28 |

29 | Your first goto for reference should ALWAYS be the header files. They are extremely well documented. Please read them. 30 |

31 | 32 |

33 | Did I mention you should read the headers? They're docemented very nicely, in plain english. 34 |

35 | 36 |

37 | If you have any questions you are welcome to post to the CocoaAsyncSocket mailing list:
38 | http://groups.google.com/group/cocoaasyncsocket
39 |
40 | The list is archived, and available for browsing online.
41 | You may be able to instantly find the answer you're looking for with a quick search.
42 |

43 | 44 |

We hope the CocoaAsyncSocket project can provide you with powerful and easy to use networking libraries.

45 | 46 | 47 | -------------------------------------------------------------------------------- /Source/Vendor/CocoaLumberjack/DDASLLogger.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | 4 | #import "DDLog.h" 5 | 6 | /** 7 | * Welcome to Cocoa Lumberjack! 8 | * 9 | * The project page has a wealth of documentation if you have any questions. 10 | * https://github.com/CocoaLumberjack/CocoaLumberjack 11 | * 12 | * If you're new to the project you may wish to read the "Getting Started" wiki. 13 | * https://github.com/CocoaLumberjack/CocoaLumberjack/wiki/GettingStarted 14 | * 15 | * 16 | * This class provides a logger for the Apple System Log facility. 17 | * 18 | * As described in the "Getting Started" page, 19 | * the traditional NSLog() function directs it's output to two places: 20 | * 21 | * - Apple System Log 22 | * - StdErr (if stderr is a TTY) so log statements show up in Xcode console 23 | * 24 | * To duplicate NSLog() functionality you can simply add this logger and a tty logger. 25 | * However, if you instead choose to use file logging (for faster performance), 26 | * you may choose to use a file logger and a tty logger. 27 | **/ 28 | 29 | @interface DDASLLogger : DDAbstractLogger 30 | { 31 | aslclient client; 32 | } 33 | 34 | + (instancetype)sharedInstance; 35 | 36 | // Inherited from DDAbstractLogger 37 | 38 | // - (id )logFormatter; 39 | // - (void)setLogFormatter:(id )formatter; 40 | 41 | @end 42 | -------------------------------------------------------------------------------- /Source/Vendor/CocoaLumberjack/DDASLLogger.m: -------------------------------------------------------------------------------- 1 | #import "DDASLLogger.h" 2 | 3 | #import 4 | 5 | /** 6 | * Welcome to Cocoa Lumberjack! 7 | * 8 | * The project page has a wealth of documentation if you have any questions. 9 | * https://github.com/CocoaLumberjack/CocoaLumberjack 10 | * 11 | * If you're new to the project you may wish to read the "Getting Started" wiki. 12 | * https://github.com/CocoaLumberjack/CocoaLumberjack/wiki/GettingStarted 13 | **/ 14 | 15 | #if ! __has_feature(objc_arc) 16 | #warning This file must be compiled with ARC. Use -fobjc-arc flag (or convert project to ARC). 17 | #endif 18 | 19 | 20 | @implementation DDASLLogger 21 | 22 | static DDASLLogger *sharedInstance; 23 | 24 | /** 25 | * The runtime sends initialize to each class in a program exactly one time just before the class, 26 | * or any class that inherits from it, is sent its first message from within the program. (Thus the 27 | * method may never be invoked if the class is not used.) The runtime sends the initialize message to 28 | * classes in a thread-safe manner. Superclasses receive this message before their subclasses. 29 | * 30 | * This method may also be called directly (assumably by accident), hence the safety mechanism. 31 | **/ 32 | + (void)initialize 33 | { 34 | static BOOL initialized = NO; 35 | if (!initialized) 36 | { 37 | initialized = YES; 38 | 39 | sharedInstance = [[[self class] alloc] init]; 40 | } 41 | } 42 | 43 | + (instancetype)sharedInstance 44 | { 45 | return sharedInstance; 46 | } 47 | 48 | - (id)init 49 | { 50 | if (sharedInstance != nil) 51 | { 52 | return nil; 53 | } 54 | 55 | if ((self = [super init])) 56 | { 57 | // A default asl client is provided for the main thread, 58 | // but background threads need to create their own client. 59 | 60 | client = asl_open(NULL, "com.apple.console", 0); 61 | } 62 | return self; 63 | } 64 | 65 | - (void)logMessage:(DDLogMessage *)logMessage 66 | { 67 | NSString *logMsg = logMessage->logMsg; 68 | 69 | if (formatter) 70 | { 71 | logMsg = [formatter formatLogMessage:logMessage]; 72 | } 73 | 74 | if (logMsg) 75 | { 76 | const char *msg = [logMsg UTF8String]; 77 | 78 | int aslLogLevel; 79 | switch (logMessage->logFlag) 80 | { 81 | // Note: By default ASL will filter anything above level 5 (Notice). 82 | // So our mappings shouldn't go above that level. 83 | 84 | case LOG_FLAG_ERROR : aslLogLevel = ASL_LEVEL_ALERT; break; 85 | case LOG_FLAG_WARN : aslLogLevel = ASL_LEVEL_CRIT; break; 86 | case LOG_FLAG_INFO : aslLogLevel = ASL_LEVEL_ERR; break; 87 | case LOG_FLAG_DEBUG : aslLogLevel = ASL_LEVEL_WARNING; break; 88 | default : aslLogLevel = ASL_LEVEL_NOTICE; break; 89 | } 90 | 91 | asl_log(client, NULL, aslLogLevel, "%s", msg); 92 | } 93 | } 94 | 95 | - (NSString *)loggerName 96 | { 97 | return @"cocoa.lumberjack.aslLogger"; 98 | } 99 | 100 | @end 101 | -------------------------------------------------------------------------------- /Source/Vendor/CocoaLumberjack/DDAbstractDatabaseLogger.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | #import "DDLog.h" 4 | 5 | /** 6 | * Welcome to Cocoa Lumberjack! 7 | * 8 | * The project page has a wealth of documentation if you have any questions. 9 | * https://github.com/CocoaLumberjack/CocoaLumberjack 10 | * 11 | * If you're new to the project you may wish to read the "Getting Started" wiki. 12 | * https://github.com/CocoaLumberjack/CocoaLumberjack/wiki/GettingStarted 13 | * 14 | * 15 | * This class provides an abstract implementation of a database logger. 16 | * 17 | * That is, it provides the base implementation for a database logger to build atop of. 18 | * All that is needed for a concrete database logger is to extend this class 19 | * and override the methods in the implementation file that are prefixed with "db_". 20 | **/ 21 | 22 | @interface DDAbstractDatabaseLogger : DDAbstractLogger { 23 | @protected 24 | NSUInteger saveThreshold; 25 | NSTimeInterval saveInterval; 26 | NSTimeInterval maxAge; 27 | NSTimeInterval deleteInterval; 28 | BOOL deleteOnEverySave; 29 | 30 | BOOL saveTimerSuspended; 31 | NSUInteger unsavedCount; 32 | dispatch_time_t unsavedTime; 33 | dispatch_source_t saveTimer; 34 | dispatch_time_t lastDeleteTime; 35 | dispatch_source_t deleteTimer; 36 | } 37 | 38 | /** 39 | * Specifies how often to save the data to disk. 40 | * Since saving is an expensive operation (disk io) it is not done after every log statement. 41 | * These properties allow you to configure how/when the logger saves to disk. 42 | * 43 | * A save is done when either (whichever happens first): 44 | * 45 | * - The number of unsaved log entries reaches saveThreshold 46 | * - The amount of time since the oldest unsaved log entry was created reaches saveInterval 47 | * 48 | * You can optionally disable the saveThreshold by setting it to zero. 49 | * If you disable the saveThreshold you are entirely dependent on the saveInterval. 50 | * 51 | * You can optionally disable the saveInterval by setting it to zero (or a negative value). 52 | * If you disable the saveInterval you are entirely dependent on the saveThreshold. 53 | * 54 | * It's not wise to disable both saveThreshold and saveInterval. 55 | * 56 | * The default saveThreshold is 500. 57 | * The default saveInterval is 60 seconds. 58 | **/ 59 | @property (assign, readwrite) NSUInteger saveThreshold; 60 | @property (assign, readwrite) NSTimeInterval saveInterval; 61 | 62 | /** 63 | * It is likely you don't want the log entries to persist forever. 64 | * Doing so would allow the database to grow infinitely large over time. 65 | * 66 | * The maxAge property provides a way to specify how old a log statement can get 67 | * before it should get deleted from the database. 68 | * 69 | * The deleteInterval specifies how often to sweep for old log entries. 70 | * Since deleting is an expensive operation (disk io) is is done on a fixed interval. 71 | * 72 | * An alternative to the deleteInterval is the deleteOnEverySave option. 73 | * This specifies that old log entries should be deleted during every save operation. 74 | * 75 | * You can optionally disable the maxAge by setting it to zero (or a negative value). 76 | * If you disable the maxAge then old log statements are not deleted. 77 | * 78 | * You can optionally disable the deleteInterval by setting it to zero (or a negative value). 79 | * 80 | * If you disable both deleteInterval and deleteOnEverySave then old log statements are not deleted. 81 | * 82 | * It's not wise to enable both deleteInterval and deleteOnEverySave. 83 | * 84 | * The default maxAge is 7 days. 85 | * The default deleteInterval is 5 minutes. 86 | * The default deleteOnEverySave is NO. 87 | **/ 88 | @property (assign, readwrite) NSTimeInterval maxAge; 89 | @property (assign, readwrite) NSTimeInterval deleteInterval; 90 | @property (assign, readwrite) BOOL deleteOnEverySave; 91 | 92 | /** 93 | * Forces a save of any pending log entries (flushes log entries to disk). 94 | **/ 95 | - (void)savePendingLogEntries; 96 | 97 | /** 98 | * Removes any log entries that are older than maxAge. 99 | **/ 100 | - (void)deleteOldLogEntries; 101 | 102 | @end 103 | -------------------------------------------------------------------------------- /Source/Vendor/CocoaLumberjack/DDLog+LOGV.h: -------------------------------------------------------------------------------- 1 | // 2 | // DDLog+LOGV.h 3 | // Lumberjack 4 | // 5 | // Created by Mike Pontillo on 11/20/12. 6 | // 7 | // 8 | 9 | #ifndef Lumberjack_DDLog_LOGV_h 10 | #define Lumberjack_DDLog_LOGV_h 11 | 12 | #import "DDLog.h" 13 | 14 | 15 | #define LOGV_MACRO(isAsynchronous, lvl, flg, ctx, atag, fnct, frmt, avalist) \ 16 | [DDLog log:isAsynchronous \ 17 | level:lvl \ 18 | flag:flg \ 19 | context:ctx \ 20 | file:__FILE__ \ 21 | function:fnct \ 22 | line:__LINE__ \ 23 | tag:atag \ 24 | format:frmt \ 25 | args:avalist] 26 | 27 | #define LOGV_OBJC_MACRO(async, lvl, flg, ctx, frmt, avalist) \ 28 | LOGV_MACRO(async, lvl, flg, ctx, nil, sel_getName(_cmd), frmt, avalist) 29 | 30 | #define LOGV_C_MACRO(async, lvl, flg, ctx, frmt, avalist) \ 31 | LOGV_MACRO(async, lvl, flg, ctx, nil, __FUNCTION__, frmt, avalist) 32 | 33 | 34 | 35 | #define SYNC_LOGV_OBJC_MACRO(lvl, flg, ctx, frmt, avalist) \ 36 | LOGV_OBJC_MACRO( NO, lvl, flg, ctx, frmt, avalist) 37 | 38 | #define ASYNC_LOGV_OBJC_MACRO(lvl, flg, ctx, frmt, avalist) \ 39 | LOGV_OBJC_MACRO(YES, lvl, flg, ctx, frmt, avalist) 40 | 41 | #define SYNC_LOGV_C_MACRO(lvl, flg, ctx, frmt, avalist) \ 42 | LOGV_C_MACRO( NO, lvl, flg, ctx, frmt, avalist) 43 | 44 | #define ASYNC_LOGV_C_MACRO(lvl, flg, ctx, frmt, avalist) \ 45 | LOGV_C_MACRO(YES, lvl, flg, ctx, frmt, avalist) 46 | 47 | 48 | 49 | #define LOGV_MAYBE(async, lvl, flg, ctx, fnct, frmt, avalist) \ 50 | do { if(lvl & flg) LOGV_MACRO(async, lvl, flg, ctx, nil, fnct, frmt, avalist); } while(0) 51 | 52 | #define LOGV_OBJC_MAYBE(async, lvl, flg, ctx, frmt, avalist) \ 53 | LOGV_MAYBE(async, lvl, flg, ctx, sel_getName(_cmd), frmt, avalist) 54 | 55 | #define LOGV_C_MAYBE(async, lvl, flg, ctx, frmt, avalist) \ 56 | LOGV_MAYBE(async, lvl, flg, ctx, __FUNCTION__, frmt, avalist) 57 | 58 | #define SYNC_LOGV_OBJC_MAYBE(lvl, flg, ctx, frmt, avalist) \ 59 | LOGV_OBJC_MAYBE( NO, lvl, flg, ctx, frmt, avalist) 60 | 61 | #define ASYNC_LOGV_OBJC_MAYBE(lvl, flg, ctx, frmt, avalist) \ 62 | LOGV_OBJC_MAYBE(YES, lvl, flg, ctx, frmt, avalist) 63 | 64 | #define SYNC_LOGV_C_MAYBE(lvl, flg, ctx, frmt, avalist) \ 65 | LOGV_C_MAYBE( NO, lvl, flg, ctx, frmt, avalist) 66 | 67 | #define ASYNC_LOGV_C_MAYBE(lvl, flg, ctx, frmt, avalist) \ 68 | LOGV_C_MAYBE(YES, lvl, flg, ctx, frmt, avalist) 69 | 70 | 71 | 72 | #define LOGV_OBJC_TAG_MACRO(async, lvl, flg, ctx, tag, frmt, avalist) \ 73 | LOGV_MACRO(async, lvl, flg, ctx, tag, sel_getName(_cmd), frmt, avalist) 74 | 75 | #define LOGV_C_TAG_MACRO(async, lvl, flg, ctx, tag, frmt, avalist) \ 76 | LOGV_MACRO(async, lvl, flg, ctx, tag, __FUNCTION__, frmt, avalist) 77 | 78 | #define LOGV_TAG_MAYBE(async, lvl, flg, ctx, tag, fnct, frmt, avalist) \ 79 | do { if(lvl & flg) LOGV_MACRO(async, lvl, flg, ctx, tag, fnct, frmt, avalist); } while(0) 80 | 81 | #define LOGV_OBJC_TAG_MAYBE(async, lvl, flg, ctx, tag, frmt, avalist) \ 82 | LOGV_TAG_MAYBE(async, lvl, flg, ctx, tag, sel_getName(_cmd), frmt, avalist) 83 | 84 | #define LOGV_C_TAG_MAYBE(async, lvl, flg, ctx, tag, frmt, avalist) \ 85 | LOGV_TAG_MAYBE(async, lvl, flg, ctx, tag, __FUNCTION__, frmt, avalist) 86 | 87 | 88 | 89 | #define DDLogvError(frmt, avalist) LOGV_OBJC_MAYBE(LOG_ASYNC_ERROR, ddLogLevel, LOG_FLAG_ERROR, 0, frmt, avalist) 90 | #define DDLogvWarn(frmt, avalist) LOGV_OBJC_MAYBE(LOG_ASYNC_WARN, ddLogLevel, LOG_FLAG_WARN, 0, frmt, avalist) 91 | #define DDLogvInfo(frmt, avalist) LOGV_OBJC_MAYBE(LOG_ASYNC_INFO, ddLogLevel, LOG_FLAG_INFO, 0, frmt, avalist) 92 | #define DDLogvVerbose(frmt, avalist) LOGV_OBJC_MAYBE(LOG_ASYNC_VERBOSE, ddLogLevel, LOG_FLAG_VERBOSE, 0, frmt, avalist) 93 | 94 | #define DDLogvCError(frmt, avalist) LOGV_C_MAYBE(LOG_ASYNC_ERROR, ddLogLevel, LOG_FLAG_ERROR, 0, frmt, avalist) 95 | #define DDLogvCWarn(frmt, avalist) LOGV_C_MAYBE(LOG_ASYNC_WARN, ddLogLevel, LOG_FLAG_WARN, 0, frmt, avalist) 96 | #define DDLogvCInfo(frmt, avalist) LOGV_C_MAYBE(LOG_ASYNC_INFO, ddLogLevel, LOG_FLAG_INFO, 0, frmt, avalist) 97 | #define DDLogvCVerbose(frmt, avalist) LOGV_C_MAYBE(LOG_ASYNC_VERBOSE, ddLogLevel, LOG_FLAG_VERBOSE, 0, frmt, avalist) 98 | 99 | #endif 100 | -------------------------------------------------------------------------------- /Source/Vendor/CocoaLumberjack/Extensions/DDContextFilterLogFormatter.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import "DDLog.h" 3 | 4 | /** 5 | * Welcome to Cocoa Lumberjack! 6 | * 7 | * The project page has a wealth of documentation if you have any questions. 8 | * https://github.com/CocoaLumberjack/CocoaLumberjack 9 | * 10 | * If you're new to the project you may wish to read the "Getting Started" page. 11 | * https://github.com/CocoaLumberjack/CocoaLumberjack/wiki/GettingStarted 12 | * 13 | * 14 | * This class provides a log formatter that filters log statements from a logging context not on the whitelist. 15 | * 16 | * A log formatter can be added to any logger to format and/or filter its output. 17 | * You can learn more about log formatters here: 18 | * https://github.com/CocoaLumberjack/CocoaLumberjack/wiki/CustomFormatters 19 | * 20 | * You can learn more about logging context's here: 21 | * https://github.com/CocoaLumberjack/CocoaLumberjack/wiki/CustomContext 22 | * 23 | * But here's a quick overview / refresher: 24 | * 25 | * Every log statement has a logging context. 26 | * These come from the underlying logging macros defined in DDLog.h. 27 | * The default logging context is zero. 28 | * You can define multiple logging context's for use in your application. 29 | * For example, logically separate parts of your app each have a different logging context. 30 | * Also 3rd party frameworks that make use of Lumberjack generally use their own dedicated logging context. 31 | **/ 32 | @interface DDContextWhitelistFilterLogFormatter : NSObject 33 | 34 | - (id)init; 35 | 36 | - (void)addToWhitelist:(int)loggingContext; 37 | - (void)removeFromWhitelist:(int)loggingContext; 38 | 39 | - (NSArray *)whitelist; 40 | 41 | - (BOOL)isOnWhitelist:(int)loggingContext; 42 | 43 | @end 44 | 45 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 46 | #pragma mark - 47 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 48 | 49 | /** 50 | * This class provides a log formatter that filters log statements from a logging context on the blacklist. 51 | **/ 52 | @interface DDContextBlacklistFilterLogFormatter : NSObject 53 | 54 | - (id)init; 55 | 56 | - (void)addToBlacklist:(int)loggingContext; 57 | - (void)removeFromBlacklist:(int)loggingContext; 58 | 59 | - (NSArray *)blacklist; 60 | 61 | - (BOOL)isOnBlacklist:(int)loggingContext; 62 | 63 | @end 64 | -------------------------------------------------------------------------------- /Source/Vendor/CocoaLumberjack/Extensions/DDContextFilterLogFormatter.m: -------------------------------------------------------------------------------- 1 | #import "DDContextFilterLogFormatter.h" 2 | #import 3 | 4 | /** 5 | * Welcome to Cocoa Lumberjack! 6 | * 7 | * The project page has a wealth of documentation if you have any questions. 8 | * https://github.com/CocoaLumberjack/CocoaLumberjack 9 | * 10 | * If you're new to the project you may wish to read the "Getting Started" wiki. 11 | * https://github.com/CocoaLumberjack/CocoaLumberjack/wiki/GettingStarted 12 | **/ 13 | 14 | #if ! __has_feature(objc_arc) 15 | #warning This file must be compiled with ARC. Use -fobjc-arc flag (or convert project to ARC). 16 | #endif 17 | 18 | @interface DDLoggingContextSet : NSObject 19 | 20 | - (void)addToSet:(int)loggingContext; 21 | - (void)removeFromSet:(int)loggingContext; 22 | 23 | - (NSArray *)currentSet; 24 | 25 | - (BOOL)isInSet:(int)loggingContext; 26 | 27 | @end 28 | 29 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 30 | #pragma mark - 31 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 32 | 33 | @implementation DDContextWhitelistFilterLogFormatter 34 | { 35 | DDLoggingContextSet *contextSet; 36 | } 37 | 38 | - (id)init 39 | { 40 | if ((self = [super init])) 41 | { 42 | contextSet = [[DDLoggingContextSet alloc] init]; 43 | } 44 | return self; 45 | } 46 | 47 | 48 | - (void)addToWhitelist:(int)loggingContext 49 | { 50 | [contextSet addToSet:loggingContext]; 51 | } 52 | 53 | - (void)removeFromWhitelist:(int)loggingContext 54 | { 55 | [contextSet removeFromSet:loggingContext]; 56 | } 57 | 58 | - (NSArray *)whitelist 59 | { 60 | return [contextSet currentSet]; 61 | } 62 | 63 | - (BOOL)isOnWhitelist:(int)loggingContext 64 | { 65 | return [contextSet isInSet:loggingContext]; 66 | } 67 | 68 | - (NSString *)formatLogMessage:(DDLogMessage *)logMessage 69 | { 70 | if ([self isOnWhitelist:logMessage->logContext]) 71 | return logMessage->logMsg; 72 | else 73 | return nil; 74 | } 75 | 76 | @end 77 | 78 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 79 | #pragma mark - 80 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 81 | 82 | @implementation DDContextBlacklistFilterLogFormatter 83 | { 84 | DDLoggingContextSet *contextSet; 85 | } 86 | 87 | - (id)init 88 | { 89 | if ((self = [super init])) 90 | { 91 | contextSet = [[DDLoggingContextSet alloc] init]; 92 | } 93 | return self; 94 | } 95 | 96 | 97 | - (void)addToBlacklist:(int)loggingContext 98 | { 99 | [contextSet addToSet:loggingContext]; 100 | } 101 | 102 | - (void)removeFromBlacklist:(int)loggingContext 103 | { 104 | [contextSet removeFromSet:loggingContext]; 105 | } 106 | 107 | - (NSArray *)blacklist 108 | { 109 | return [contextSet currentSet]; 110 | } 111 | 112 | - (BOOL)isOnBlacklist:(int)loggingContext 113 | { 114 | return [contextSet isInSet:loggingContext]; 115 | } 116 | 117 | - (NSString *)formatLogMessage:(DDLogMessage *)logMessage 118 | { 119 | if ([self isOnBlacklist:logMessage->logContext]) 120 | return nil; 121 | else 122 | return logMessage->logMsg; 123 | } 124 | 125 | @end 126 | 127 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 128 | #pragma mark - 129 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 130 | 131 | @implementation DDLoggingContextSet 132 | { 133 | OSSpinLock lock; 134 | NSMutableSet *set; 135 | } 136 | 137 | - (id)init 138 | { 139 | if ((self = [super init])) 140 | { 141 | set = [[NSMutableSet alloc] init]; 142 | } 143 | return self; 144 | } 145 | 146 | 147 | - (void)addToSet:(int)loggingContext 148 | { 149 | OSSpinLockLock(&lock); 150 | { 151 | [set addObject:@(loggingContext)]; 152 | } 153 | OSSpinLockUnlock(&lock); 154 | } 155 | 156 | - (void)removeFromSet:(int)loggingContext 157 | { 158 | OSSpinLockLock(&lock); 159 | { 160 | [set removeObject:@(loggingContext)]; 161 | } 162 | OSSpinLockUnlock(&lock); 163 | } 164 | 165 | - (NSArray *)currentSet 166 | { 167 | NSArray *result = nil; 168 | 169 | OSSpinLockLock(&lock); 170 | { 171 | result = [set allObjects]; 172 | } 173 | OSSpinLockUnlock(&lock); 174 | 175 | return result; 176 | } 177 | 178 | - (BOOL)isInSet:(int)loggingContext 179 | { 180 | BOOL result = NO; 181 | 182 | OSSpinLockLock(&lock); 183 | { 184 | result = [set containsObject:@(loggingContext)]; 185 | } 186 | OSSpinLockUnlock(&lock); 187 | 188 | return result; 189 | } 190 | 191 | @end 192 | -------------------------------------------------------------------------------- /Source/Vendor/CocoaLumberjack/Extensions/DDDispatchQueueLogFormatter.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | #import "DDLog.h" 4 | 5 | 6 | /** 7 | * Welcome to Cocoa Lumberjack! 8 | * 9 | * The project page has a wealth of documentation if you have any questions. 10 | * https://github.com/CocoaLumberjack/CocoaLumberjack 11 | * 12 | * If you're new to the project you may wish to read the "Getting Started" page. 13 | * https://github.com/CocoaLumberjack/CocoaLumberjack/wiki/GettingStarted 14 | * 15 | * 16 | * This class provides a log formatter that prints the dispatch_queue label instead of the mach_thread_id. 17 | * 18 | * A log formatter can be added to any logger to format and/or filter its output. 19 | * You can learn more about log formatters here: 20 | * https://github.com/CocoaLumberjack/CocoaLumberjack/wiki/CustomFormatters 21 | * 22 | * A typical NSLog (or DDTTYLogger) prints detailed info as [:]. 23 | * For example: 24 | * 25 | * 2011-10-17 20:21:45.435 AppName[19928:5207] Your log message here 26 | * 27 | * Where: 28 | * - 19928 = process id 29 | * - 5207 = thread id (mach_thread_id printed in hex) 30 | * 31 | * When using grand central dispatch (GCD), this information is less useful. 32 | * This is because a single serial dispatch queue may be run on any thread from an internally managed thread pool. 33 | * For example: 34 | * 35 | * 2011-10-17 20:32:31.111 AppName[19954:4d07] Message from my_serial_dispatch_queue 36 | * 2011-10-17 20:32:31.112 AppName[19954:5207] Message from my_serial_dispatch_queue 37 | * 2011-10-17 20:32:31.113 AppName[19954:2c55] Message from my_serial_dispatch_queue 38 | * 39 | * This formatter allows you to replace the standard [box:info] with the dispatch_queue name. 40 | * For example: 41 | * 42 | * 2011-10-17 20:32:31.111 AppName[img-scaling] Message from my_serial_dispatch_queue 43 | * 2011-10-17 20:32:31.112 AppName[img-scaling] Message from my_serial_dispatch_queue 44 | * 2011-10-17 20:32:31.113 AppName[img-scaling] Message from my_serial_dispatch_queue 45 | * 46 | * If the dispatch_queue doesn't have a set name, then it falls back to the thread name. 47 | * If the current thread doesn't have a set name, then it falls back to the mach_thread_id in hex (like normal). 48 | * 49 | * Note: If manually creating your own background threads (via NSThread/alloc/init or NSThread/detachNeThread), 50 | * you can use [[NSThread currentThread] setName:(NSString *)]. 51 | **/ 52 | @interface DDDispatchQueueLogFormatter : NSObject { 53 | @protected 54 | 55 | NSString *dateFormatString; 56 | } 57 | 58 | /** 59 | * Standard init method. 60 | * Configure using properties as desired. 61 | **/ 62 | - (id)init; 63 | 64 | /** 65 | * The minQueueLength restricts the minimum size of the [detail box]. 66 | * If the minQueueLength is set to 0, there is no restriction. 67 | * 68 | * For example, say a dispatch_queue has a label of "diskIO": 69 | * 70 | * If the minQueueLength is 0: [diskIO] 71 | * If the minQueueLength is 4: [diskIO] 72 | * If the minQueueLength is 5: [diskIO] 73 | * If the minQueueLength is 6: [diskIO] 74 | * If the minQueueLength is 7: [diskIO ] 75 | * If the minQueueLength is 8: [diskIO ] 76 | * 77 | * The default minQueueLength is 0 (no minimum, so [detail box] won't be padded). 78 | * 79 | * If you want every [detail box] to have the exact same width, 80 | * set both minQueueLength and maxQueueLength to the same value. 81 | **/ 82 | @property (assign) NSUInteger minQueueLength; 83 | 84 | /** 85 | * The maxQueueLength restricts the number of characters that will be inside the [detail box]. 86 | * If the maxQueueLength is 0, there is no restriction. 87 | * 88 | * For example, say a dispatch_queue has a label of "diskIO": 89 | * 90 | * If the maxQueueLength is 0: [diskIO] 91 | * If the maxQueueLength is 4: [disk] 92 | * If the maxQueueLength is 5: [diskI] 93 | * If the maxQueueLength is 6: [diskIO] 94 | * If the maxQueueLength is 7: [diskIO] 95 | * If the maxQueueLength is 8: [diskIO] 96 | * 97 | * The default maxQueueLength is 0 (no maximum, so [detail box] won't be truncated). 98 | * 99 | * If you want every [detail box] to have the exact same width, 100 | * set both minQueueLength and maxQueueLength to the same value. 101 | **/ 102 | @property (assign) NSUInteger maxQueueLength; 103 | 104 | /** 105 | * Sometimes queue labels have long names like "com.apple.main-queue", 106 | * but you'd prefer something shorter like simply "main". 107 | * 108 | * This method allows you to set such preferred replacements. 109 | * The above example is set by default. 110 | * 111 | * To remove/undo a previous replacement, invoke this method with nil for the 'shortLabel' parameter. 112 | **/ 113 | - (NSString *)replacementStringForQueueLabel:(NSString *)longLabel; 114 | - (void)setReplacementString:(NSString *)shortLabel forQueueLabel:(NSString *)longLabel; 115 | 116 | @end 117 | 118 | /** 119 | * Method declarations that make it easier to extend/modify DDDispatchQueueLogFormatter 120 | **/ 121 | @interface DDDispatchQueueLogFormatter (OverridableMethods) 122 | 123 | - (NSString *)stringFromDate:(NSDate *)date; 124 | - (NSString *)queueThreadLabelForLogMessage:(DDLogMessage *)logMessage; 125 | - (NSString *)formatLogMessage:(DDLogMessage *)logMessage; 126 | 127 | @end 128 | 129 | -------------------------------------------------------------------------------- /Source/Vendor/CocoaLumberjack/Extensions/DDMultiFormatter.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import "DDLog.h" 3 | 4 | /** 5 | * Welcome to Cocoa Lumberjack! 6 | * 7 | * The project page has a wealth of documentation if you have any questions. 8 | * https://github.com/CocoaLumberjack/CocoaLumberjack 9 | * 10 | * If you're new to the project you may wish to read the "Getting Started" page. 11 | * https://github.com/CocoaLumberjack/CocoaLumberjack/wiki/GettingStarted 12 | * 13 | * 14 | * This formatter can be used to chain different formatters together. 15 | * The log message will processed in the order of the formatters added. 16 | **/ 17 | 18 | @interface DDMultiFormatter : NSObject 19 | 20 | /** 21 | * Array of chained formatters 22 | */ 23 | @property (readonly) NSArray *formatters; 24 | 25 | - (void)addFormatter:(id)formatter; 26 | - (void)removeFormatter:(id)formatter; 27 | - (void)removeAllFormatters; 28 | - (BOOL)isFormattingWithFormatter:(id)formatter; 29 | 30 | @end 31 | -------------------------------------------------------------------------------- /Source/Vendor/CocoaLumberjack/Extensions/DDMultiFormatter.m: -------------------------------------------------------------------------------- 1 | #import "DDMultiFormatter.h" 2 | 3 | /** 4 | * Welcome to Cocoa Lumberjack! 5 | * 6 | * The project page has a wealth of documentation if you have any questions. 7 | * https://github.com/CocoaLumberjack/CocoaLumberjack 8 | * 9 | * If you're new to the project you may wish to read the "Getting Started" page. 10 | * https://github.com/CocoaLumberjack/CocoaLumberjack/wiki/GettingStarted 11 | **/ 12 | 13 | #if TARGET_OS_IPHONE 14 | // Compiling for iOS 15 | #if __IPHONE_OS_VERSION_MIN_REQUIRED >= 60000 // iOS 6.0 or later 16 | #define NEEDS_DISPATCH_RETAIN_RELEASE 0 17 | #else // iOS 5.X or earlier 18 | #define NEEDS_DISPATCH_RETAIN_RELEASE 1 19 | #endif 20 | #else 21 | // Compiling for Mac OS X 22 | #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1080 // Mac OS X 10.8 or later 23 | #define NEEDS_DISPATCH_RETAIN_RELEASE 0 24 | #else // Mac OS X 10.7 or earlier 25 | #define NEEDS_DISPATCH_RETAIN_RELEASE 1 26 | #endif 27 | #endif 28 | 29 | 30 | @interface DDMultiFormatter () 31 | 32 | - (DDLogMessage *)logMessageForLine:(NSString *)line originalMessage:(DDLogMessage *)message; 33 | 34 | @end 35 | 36 | 37 | @implementation DDMultiFormatter { 38 | dispatch_queue_t _queue; 39 | NSMutableArray *_formatters; 40 | } 41 | 42 | - (id)init { 43 | self = [super init]; 44 | if (self) { 45 | #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 46 | _queue = dispatch_queue_create("cocoa.lumberjack.multiformatter", DISPATCH_QUEUE_CONCURRENT); 47 | #else 48 | _queue = dispatch_queue_create("cocoa.lumberjack.multiformatter", NULL); 49 | #endif 50 | _formatters = [NSMutableArray new]; 51 | } 52 | 53 | return self; 54 | } 55 | 56 | #if NEEDS_DISPATCH_RETAIN_RELEASE 57 | - (void)dealloc { 58 | dispatch_release(_queue); 59 | } 60 | #endif 61 | 62 | #pragma mark Processing 63 | 64 | - (NSString *)formatLogMessage:(DDLogMessage *)logMessage { 65 | __block NSString *line = logMessage->logMsg; 66 | 67 | dispatch_sync(_queue, ^{ 68 | for (id formatter in _formatters) { 69 | DDLogMessage *message = [self logMessageForLine:line originalMessage:logMessage]; 70 | line = [formatter formatLogMessage:message]; 71 | 72 | if (!line) { 73 | break; 74 | } 75 | } 76 | }); 77 | 78 | return line; 79 | } 80 | 81 | - (DDLogMessage *)logMessageForLine:(NSString *)line originalMessage:(DDLogMessage *)message { 82 | DDLogMessage *newMessage = [message copy]; 83 | newMessage->logMsg = line; 84 | return newMessage; 85 | } 86 | 87 | #pragma mark Formatters 88 | 89 | - (NSArray *)formatters { 90 | __block NSArray *formatters; 91 | 92 | dispatch_sync(_queue, ^{ 93 | formatters = [_formatters copy]; 94 | }); 95 | 96 | return formatters; 97 | } 98 | 99 | - (void)addFormatter:(id)formatter { 100 | dispatch_barrier_async(_queue, ^{ 101 | [_formatters addObject:formatter]; 102 | }); 103 | } 104 | 105 | - (void)removeFormatter:(id)formatter { 106 | dispatch_barrier_async(_queue, ^{ 107 | [_formatters removeObject:formatter]; 108 | }); 109 | } 110 | 111 | - (void)removeAllFormatters { 112 | dispatch_barrier_async(_queue, ^{ 113 | [_formatters removeAllObjects]; 114 | }); 115 | } 116 | 117 | - (BOOL)isFormattingWithFormatter:(id)formatter { 118 | __block BOOL hasFormatter; 119 | 120 | dispatch_sync(_queue, ^{ 121 | hasFormatter = [_formatters containsObject:formatter]; 122 | }); 123 | 124 | return hasFormatter; 125 | } 126 | 127 | @end 128 | -------------------------------------------------------------------------------- /Source/Vendor/CocoaLumberjack/Extensions/README.txt: -------------------------------------------------------------------------------- 1 | This folder contains some sample formatters that may be helpful. 2 | 3 | Feel free to change them, extend them, or use them as the basis for your own custom formatter(s). 4 | 5 | More information about creating your own custom formatters can be found on the wiki: 6 | https://github.com/CocoaLumberjack/CocoaLumberjack/wiki/CustomFormatters 7 | 8 | -------------------------------------------------------------------------------- /Tests/Mac/CocoaAsyncSocket.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Tests/Mac/CocoaAsyncSocket.xcodeproj/xcshareddata/xcschemes/CocoaAsyncSocketTestsMac.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 33 | 39 | 40 | 41 | 42 | 43 | 49 | 50 | 51 | 52 | 61 | 62 | 68 | 69 | 70 | 71 | 72 | 73 | 79 | 80 | 86 | 87 | 88 | 89 | 91 | 92 | 95 | 96 | 97 | -------------------------------------------------------------------------------- /Tests/Mac/CocoaAsyncSocket.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Tests/Mac/GCDAsyncSocketUNTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // GCDAsyncSocketConnectionTests.m 3 | // GCDAsyncSocketConnectionTests 4 | // 5 | // Created by Christopher Ballinger on 10/31/14. 6 | // 7 | // 8 | 9 | #import 10 | #import 11 | @import CocoaAsyncSocket; 12 | 13 | @interface GCDAsyncSocketUNTests : XCTestCase 14 | @property (nonatomic, strong) NSURL *url; 15 | @property (nonatomic, strong) GCDAsyncSocket *clientSocket; 16 | @property (nonatomic, strong) GCDAsyncSocket *serverSocket; 17 | @property (nonatomic, strong) GCDAsyncSocket *acceptedServerSocket; 18 | @property (nonatomic, strong) NSData *readData; 19 | 20 | @property (nonatomic, strong) XCTestExpectation *expectation; 21 | @end 22 | 23 | @implementation GCDAsyncSocketUNTests 24 | 25 | - (void)setUp { 26 | [super setUp]; 27 | // Put setup code here. This method is called before the invocation of each test method in the class. 28 | self.url = [NSURL fileURLWithPath:@"/tmp/GCDAsyncSocketUNTests"]; 29 | self.clientSocket = [[GCDAsyncSocket alloc] initWithDelegate:self delegateQueue:dispatch_get_main_queue()]; 30 | self.serverSocket = [[GCDAsyncSocket alloc] initWithDelegate:self delegateQueue:dispatch_get_main_queue()]; 31 | } 32 | 33 | - (void)tearDown { 34 | // Put teardown code here. This method is called after the invocation of each test method in the class. 35 | [super tearDown]; 36 | [self.clientSocket disconnect]; 37 | [self.serverSocket disconnect]; 38 | [self.acceptedServerSocket disconnect]; 39 | self.clientSocket = nil; 40 | self.serverSocket = nil; 41 | self.acceptedServerSocket = nil; 42 | [[NSFileManager defaultManager] removeItemAtURL:self.url error:nil]; 43 | } 44 | 45 | - (void)testFullConnection { 46 | NSError *error = nil; 47 | BOOL success = NO; 48 | success = [self.serverSocket acceptOnUrl:self.url error:&error]; 49 | XCTAssertTrue(success, @"Server failed setting up socket at path %@ %@", self.url.path, error); 50 | success = [self.clientSocket connectToUrl:self.url withTimeout:-1 error:&error]; 51 | XCTAssertTrue(success, @"Client failed connecting to server socket at path %@ %@", self.url.path, error); 52 | 53 | self.expectation = [self expectationWithDescription:@"Test Full Connection"]; 54 | [self waitForExpectationsWithTimeout:30 handler:^(NSError *error) { 55 | if (error) { 56 | NSLog(@"Error establishing test connection"); 57 | } 58 | }]; 59 | } 60 | 61 | /**** BROKEN TESTS ******* 62 | 63 | 64 | - (void)testTransferFromClient { 65 | 66 | NSData *testData = [@"ThisTestRocks!!!" dataUsingEncoding:NSUTF8StringEncoding]; 67 | 68 | // set up and conncet to socket 69 | [self.serverSocket acceptOnUrl:self.url error:nil]; 70 | [self.clientSocket connectToUrl:self.url withTimeout:-1 error:nil]; 71 | 72 | // wait for connection 73 | self.expectation = [self expectationWithDescription:@"Socket Connected"]; 74 | [self waitForExpectationsWithTimeout:30 handler:^(NSError *error) { 75 | 76 | // start reading 77 | [self.acceptedServerSocket readDataWithTimeout:-1 tag:0]; 78 | 79 | // send data 80 | self.expectation = [self expectationWithDescription:@"Data Sent"]; 81 | [self.clientSocket writeData:testData withTimeout:-1 tag:0]; 82 | [self waitForExpectationsWithTimeout:1 handler:^(NSError *error) { 83 | if (error) { 84 | return NSLog(@"Error reading data"); 85 | } 86 | XCTAssertTrue([testData isEqual:self.readData], @"Read data did not match test data"); 87 | }]; 88 | }]; 89 | } 90 | 91 | - (void)testTransferFromServer { 92 | 93 | NSData *testData = [@"ThisTestRocks!!!" dataUsingEncoding:NSUTF8StringEncoding]; 94 | 95 | // set up and conncet to socket 96 | [self.serverSocket acceptOnUrl:self.url error:nil]; 97 | [self.clientSocket connectToUrl:self.url withTimeout:-1 error:nil]; 98 | 99 | // wait for connection 100 | self.expectation = [self expectationWithDescription:@"Socket Connected"]; 101 | [self waitForExpectationsWithTimeout:30 handler:^(NSError *error) { 102 | 103 | // start reading 104 | [self.clientSocket readDataWithTimeout:-1 tag:0]; 105 | 106 | // send data 107 | self.expectation = [self expectationWithDescription:@"Data Sent"]; 108 | [self.acceptedServerSocket writeData:testData withTimeout:-1 tag:0]; 109 | [self waitForExpectationsWithTimeout:1 handler:^(NSError *error) { 110 | if (error) { 111 | return NSLog(@"Error reading data"); 112 | } 113 | XCTAssertTrue([testData isEqual:self.readData], @"Read data did not match test data"); 114 | }]; 115 | }]; 116 | } 117 | 118 | **************/ 119 | 120 | #pragma mark GCDAsyncSocketDelegate methods 121 | 122 | /** 123 | * Called when a socket accepts a connection. 124 | * Another socket is automatically spawned to handle it. 125 | * 126 | * You must retain the newSocket if you wish to handle the connection. 127 | * Otherwise the newSocket instance will be released and the spawned connection will be closed. 128 | * 129 | * By default the new socket will have the same delegate and delegateQueue. 130 | * You may, of course, change this at any time. 131 | **/ 132 | - (void)socket:(GCDAsyncSocket *)sock didAcceptNewSocket:(GCDAsyncSocket *)newSocket { 133 | NSLog(@"didAcceptNewSocket %@ %@", sock, newSocket); 134 | self.acceptedServerSocket = newSocket; 135 | } 136 | 137 | /** 138 | * Called when a socket connects and is ready for reading and writing. 139 | * The host parameter will be an IP address, not a DNS name. 140 | **/ 141 | - (void)socket:(GCDAsyncSocket *)sock didConnectToUrl:(NSURL *)url { 142 | NSLog(@"didConnectToUrl %@", url); 143 | [self.expectation fulfill]; 144 | } 145 | 146 | /** 147 | * Called when a socket has completed reading the requested data into memory. 148 | * Not called if there is an error. 149 | **/ 150 | - (void)socket:(GCDAsyncSocket *)sock didReadData:(NSData *)data withTag:(long)tag { 151 | NSLog(@"didReadData: %@ tag: %ld", data, tag); 152 | self.readData = data; 153 | [self.expectation fulfill]; 154 | } 155 | 156 | 157 | @end 158 | -------------------------------------------------------------------------------- /Tests/Mac/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | com.chrisballinger.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /Tests/Mac/Podfile: -------------------------------------------------------------------------------- 1 | source 'https://github.com/CocoaPods/Specs.git' 2 | 3 | use_frameworks! 4 | 5 | target :CocoaAsyncSocketTestsMac do 6 | platform :osx, '10.8' 7 | pod 'CocoaAsyncSocket', :path => '../../CocoaAsyncSocket.podspec' 8 | end -------------------------------------------------------------------------------- /Tests/Mac/Podfile.lock: -------------------------------------------------------------------------------- 1 | PODS: 2 | - CocoaAsyncSocket (7.4.2): 3 | - CocoaAsyncSocket/All (= 7.4.2) 4 | - CocoaAsyncSocket/All (7.4.2): 5 | - CocoaAsyncSocket/GCD 6 | - CocoaAsyncSocket/RunLoop 7 | - CocoaAsyncSocket/GCD (7.4.2) 8 | - CocoaAsyncSocket/RunLoop (7.4.2) 9 | 10 | DEPENDENCIES: 11 | - CocoaAsyncSocket (from `../../CocoaAsyncSocket.podspec`) 12 | 13 | EXTERNAL SOURCES: 14 | CocoaAsyncSocket: 15 | :path: "../../CocoaAsyncSocket.podspec" 16 | 17 | SPEC CHECKSUMS: 18 | CocoaAsyncSocket: ea27dc2477a5e83223ca93531ad4508180744c35 19 | 20 | COCOAPODS: 0.39.0 21 | -------------------------------------------------------------------------------- /Tests/Shared/GCDAsyncSocketConnectionTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // GCDAsyncSocketConnectionTests.m 3 | // GCDAsyncSocketConnectionTests 4 | // 5 | // Created by Christopher Ballinger on 10/31/14. 6 | // 7 | // 8 | 9 | #import 10 | #import 11 | @import CocoaAsyncSocket; 12 | 13 | static const uint16_t kTestPort = 30301; 14 | 15 | @interface GCDAsyncSocketConnectionTests : XCTestCase 16 | @property (nonatomic, strong) GCDAsyncSocket *clientSocket; 17 | @property (nonatomic, strong) GCDAsyncSocket *serverSocket; 18 | @property (nonatomic, strong) GCDAsyncSocket *acceptedServerSocket; 19 | 20 | @property (nonatomic, strong) XCTestExpectation *expectation; 21 | @end 22 | 23 | @implementation GCDAsyncSocketConnectionTests 24 | 25 | - (void)setUp { 26 | [super setUp]; 27 | // Put setup code here. This method is called before the invocation of each test method in the class. 28 | self.clientSocket = [[GCDAsyncSocket alloc] initWithDelegate:self delegateQueue:dispatch_get_main_queue()]; 29 | self.serverSocket = [[GCDAsyncSocket alloc] initWithDelegate:self delegateQueue:dispatch_get_main_queue()]; 30 | } 31 | 32 | - (void)tearDown { 33 | // Put teardown code here. This method is called after the invocation of each test method in the class. 34 | [super tearDown]; 35 | [self.clientSocket disconnect]; 36 | [self.serverSocket disconnect]; 37 | [self.acceptedServerSocket disconnect]; 38 | self.clientSocket = nil; 39 | self.serverSocket = nil; 40 | self.acceptedServerSocket = nil; 41 | } 42 | 43 | - (void)testFullConnection { 44 | NSError *error = nil; 45 | BOOL success = NO; 46 | success = [self.serverSocket acceptOnPort:kTestPort error:&error]; 47 | XCTAssertTrue(success, @"Server failed setting up socket on port %d %@", kTestPort, error); 48 | success = [self.clientSocket connectToHost:@"127.0.0.1" onPort:kTestPort error:&error]; 49 | XCTAssertTrue(success, @"Client failed connecting to up server socket on port %d %@", kTestPort, error); 50 | 51 | self.expectation = [self expectationWithDescription:@"Test Full Connection"]; 52 | [self waitForExpectationsWithTimeout:30 handler:^(NSError *error) { 53 | if (error) { 54 | NSLog(@"Error establishing test connection"); 55 | } 56 | }]; 57 | } 58 | 59 | #pragma mark GCDAsyncSocketDelegate methods 60 | 61 | /** 62 | * Called when a socket accepts a connection. 63 | * Another socket is automatically spawned to handle it. 64 | * 65 | * You must retain the newSocket if you wish to handle the connection. 66 | * Otherwise the newSocket instance will be released and the spawned connection will be closed. 67 | * 68 | * By default the new socket will have the same delegate and delegateQueue. 69 | * You may, of course, change this at any time. 70 | **/ 71 | - (void)socket:(GCDAsyncSocket *)sock didAcceptNewSocket:(GCDAsyncSocket *)newSocket { 72 | NSLog(@"didAcceptNewSocket %@ %@", sock, newSocket); 73 | self.acceptedServerSocket = newSocket; 74 | } 75 | 76 | /** 77 | * Called when a socket connects and is ready for reading and writing. 78 | * The host parameter will be an IP address, not a DNS name. 79 | **/ 80 | - (void)socket:(GCDAsyncSocket *)sock didConnectToHost:(NSString *)host port:(uint16_t)port { 81 | NSLog(@"didConnectToHost %@ %@ %d", sock, host, port); 82 | [self.expectation fulfill]; 83 | } 84 | 85 | 86 | @end 87 | -------------------------------------------------------------------------------- /Tests/Shared/SwiftTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SwiftTests.swift 3 | // CocoaAsyncSocket 4 | // 5 | // Created by Chris Ballinger on 2/17/16. 6 | // 7 | // 8 | 9 | import XCTest 10 | import CocoaAsyncSocket 11 | 12 | class SwiftTests: XCTestCase, GCDAsyncSocketDelegate { 13 | 14 | let kTestPort: UInt16 = 30301 15 | 16 | var clientSocket: GCDAsyncSocket? 17 | var serverSocket: GCDAsyncSocket? 18 | var acceptedServerSocket: GCDAsyncSocket? 19 | var expectation: XCTestExpectation? 20 | 21 | override func setUp() { 22 | super.setUp() 23 | // Put setup code here. This method is called before the invocation of each test method in the class. 24 | clientSocket = GCDAsyncSocket(delegate: self, delegateQueue: dispatch_get_main_queue()) 25 | serverSocket = GCDAsyncSocket(delegate: self, delegateQueue: dispatch_get_main_queue()) 26 | } 27 | 28 | override func tearDown() { 29 | // Put teardown code here. This method is called after the invocation of each test method in the class. 30 | super.tearDown() 31 | clientSocket?.disconnect() 32 | serverSocket?.disconnect() 33 | acceptedServerSocket?.disconnect() 34 | clientSocket = nil 35 | serverSocket = nil 36 | acceptedServerSocket = nil 37 | } 38 | 39 | func testFullConnection() { 40 | // This is an example of a functional test case. 41 | // Use XCTAssert and related functions to verify your tests produce the correct results. 42 | do { 43 | try serverSocket?.acceptOnPort(kTestPort) 44 | } catch { 45 | XCTFail("\(error)") 46 | } 47 | do { 48 | try clientSocket?.connectToHost("127.0.0.1", onPort: kTestPort) 49 | } catch { 50 | XCTFail("\(error)") 51 | } 52 | expectation = expectationWithDescription("Test Full connnection") 53 | waitForExpectationsWithTimeout(30) { (error: NSError?) -> Void in 54 | if error != nil { 55 | XCTFail("\(error)") 56 | } 57 | } 58 | } 59 | 60 | 61 | //MARK:- GCDAsyncSocketDelegate 62 | func socket(sock: GCDAsyncSocket!, didAcceptNewSocket newSocket: GCDAsyncSocket!) { 63 | NSLog("didAcceptNewSocket %@ %@", sock, newSocket) 64 | acceptedServerSocket = newSocket 65 | } 66 | 67 | func socket(sock: GCDAsyncSocket!, didConnectToHost host: String!, port: UInt16) { 68 | NSLog("didConnectToHost %@ %@ %d", sock, host, port); 69 | expectation?.fulfill() 70 | } 71 | 72 | 73 | } 74 | -------------------------------------------------------------------------------- /Tests/iOS/CocoaAsyncSocket.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Tests/iOS/CocoaAsyncSocket.xcodeproj/xcshareddata/xcschemes/CocoaAsyncSocketTestsiOS.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 33 | 39 | 40 | 41 | 42 | 43 | 49 | 50 | 51 | 52 | 61 | 62 | 68 | 69 | 70 | 71 | 72 | 73 | 79 | 80 | 86 | 87 | 88 | 89 | 91 | 92 | 95 | 96 | 97 | -------------------------------------------------------------------------------- /Tests/iOS/CocoaAsyncSocket.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Tests/iOS/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | com.chrisballinger.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /Tests/iOS/Podfile: -------------------------------------------------------------------------------- 1 | source 'https://github.com/CocoaPods/Specs.git' 2 | 3 | use_frameworks! 4 | 5 | target :CocoaAsyncSocketTestsiOS do 6 | platform :ios, '8.0' 7 | pod 'CocoaAsyncSocket', :path => '../../CocoaAsyncSocket.podspec' 8 | end -------------------------------------------------------------------------------- /Tests/iOS/Podfile.lock: -------------------------------------------------------------------------------- 1 | PODS: 2 | - CocoaAsyncSocket (7.4.2): 3 | - CocoaAsyncSocket/All (= 7.4.2) 4 | - CocoaAsyncSocket/All (7.4.2): 5 | - CocoaAsyncSocket/GCD 6 | - CocoaAsyncSocket/RunLoop 7 | - CocoaAsyncSocket/GCD (7.4.2) 8 | - CocoaAsyncSocket/RunLoop (7.4.2) 9 | 10 | DEPENDENCIES: 11 | - CocoaAsyncSocket (from `../../CocoaAsyncSocket.podspec`) 12 | 13 | EXTERNAL SOURCES: 14 | CocoaAsyncSocket: 15 | :path: "../../CocoaAsyncSocket.podspec" 16 | 17 | SPEC CHECKSUMS: 18 | CocoaAsyncSocket: ea27dc2477a5e83223ca93531ad4508180744c35 19 | 20 | COCOAPODS: 0.39.0 21 | --------------------------------------------------------------------------------