Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2 | pmbaty | 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 macOS, iOS, and tvOS. The classes are described below. |
||
6 | |||
7 | ## Installation |
||
8 | |||
9 | #### CocoaPods |
||
10 | |||
11 | Install using [CocoaPods](https://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 | #### Swift Package Manager |
||
35 | |||
36 | Simply add the package dependency to your Package.swift and depend on "CocoaAsyncSocket" in the necessary targets: |
||
37 | ```swift |
||
38 | dependencies: [ |
||
39 | .package(url: "https://github.com/robbiehanson/CocoaAsyncSocket", from: "7.6.4") |
||
40 | ] |
||
41 | ``` |
||
42 | |||
43 | #### Manual |
||
44 | |||
45 | 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. |
||
46 | |||
47 | ### Importing |
||
48 | |||
49 | Using Objective-C: |
||
50 | |||
51 | ```obj-c |
||
52 | // When using Clang Modules: |
||
53 | @import CocoaAsyncSocket; |
||
54 | |||
55 | // or when not: |
||
56 | #import "GCDAsyncSocket.h" // for TCP |
||
57 | #import "GCDAsyncUdpSocket.h" // for UDP |
||
58 | ``` |
||
59 | |||
60 | Using Swift: |
||
61 | |||
62 | ```swift |
||
63 | import CocoaAsyncSocket |
||
64 | ``` |
||
65 | |||
66 | ## TCP |
||
67 | |||
68 | **GCDAsyncSocket** is a TCP/IP socket networking library built atop Grand Central Dispatch. Here are the key features available: |
||
69 | |||
70 | - Native Objective-C, fully self-contained in one class.<br/> |
||
71 | _No need to muck around with sockets or streams. This class handles everything for you._ |
||
72 | |||
73 | - Full delegate support<br/> |
||
74 | _Errors, connections, read completions, write completions, progress, and disconnections all result in a call to your delegate method._ |
||
75 | |||
76 | - Queued non-blocking reads and writes, with optional timeouts.<br/> |
||
77 | _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._ |
||
78 | |||
79 | - Automatic socket acceptance.<br/> |
||
80 | _Spin up a server socket, tell it to accept connections, and it will call you with new instances of itself for each connection._ |
||
81 | |||
82 | - Support for TCP streams over IPv4 and IPv6.<br/> |
||
83 | _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._ |
||
84 | |||
85 | - Support for TLS / SSL<br/> |
||
86 | _Secure your socket with ease using just a single method call. Available for both client and server sockets._ |
||
87 | |||
88 | - Fully GCD based and Thread-Safe<br/> |
||
89 | _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._ |
||
90 | |||
91 | ## UDP |
||
92 | |||
93 | **GCDAsyncUdpSocket** is a UDP/IP socket networking library built atop Grand Central Dispatch. Here are the key features available: |
||
94 | |||
95 | - Native Objective-C, fully self-contained in one class.<br/> |
||
96 | _No need to muck around with low-level sockets. This class handles everything for you._ |
||
97 | |||
98 | - Full delegate support.<br/> |
||
99 | _Errors, send completions, receive completions, and disconnections all result in a call to your delegate method._ |
||
100 | |||
101 | - Queued non-blocking send and receive operations, with optional timeouts.<br/> |
||
102 | _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._ |
||
103 | |||
104 | - Support for IPv4 and IPv6.<br/> |
||
105 | _Automatically send/recv using IPv4 and/or IPv6. No more worrying about multiple sockets._ |
||
106 | |||
107 | - Fully GCD based and Thread-Safe<br/> |
||
108 | _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._ |
||
109 | |||
110 | *** |
||
111 | |||
112 | For those new(ish) to networking, it's recommended you **[read the wiki](https://github.com/robbiehanson/CocoaAsyncSocket/wiki)**.<br/>_Sockets might not work exactly like you think they do..._ |
||
113 | |||
114 | **Still got questions?** Try the **[CocoaAsyncSocket Mailing List](https://groups.google.com/group/cocoaasyncsocket)**. |
||
115 | *** |
||
116 | |||
117 | Love the project? Wanna buy me a ☕️ ? (or a 🍺 😀 ): |
||
118 | |||
119 | [![donation-bitcoin](https://bitpay.com/img/donate-sm.png)](https://onename.com/robbiehanson) |
||
120 | [![donation-paypal](https://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) |
||
121 |