Latest 0.1.0
Homepage https://github.com/mikaoj/Swocket
License MIT
Platforms ios 8.0, osx 10.9, requires ARC
Authors

Logo

CI Status
Version
License
Platform

TODO

  • UDP

Usage

To run the example project, clone the repo, and run pod install from the Example directory first.

Echo Client:
let data = "Wazzzup".dataUsingEncoding(NSUTF8StringEncoding)!

// Set up a socket to localhost on port 9999
let client = Swocket.TCP.init(host: "127.0.0.1", port: 9999)

// Connect to server
client.connectAsync()

// Send message
client.sendDataAsync(data)

// Get response
client.recieveDataAsync({ (data, error) -> Void in
    // Unwrap response as string and set response label
    let response = NSString(data: data!, encoding: NSUTF8StringEncoding) as? String
    print(response)
})

// Disconnect
client.disconnectAsync()
HTTP Server:
let httpString = "HTTP/1.1 200 OKnContent-Type: text/html; charset=UTF-8"
let htmlString = "<html><head><title>Hello</title></head><body><h1>Hello World!</h1><p>I am a tiny little web server</p></body></html>"
let data = "(httpString)nn(htmlString)".dataUsingEncoding(NSUTF8StringEncoding)!

server = try! Swocket.TCP.listen(8080, onConnection: { (client) -> () in
    try! client.recieveData() // Ignore what client requests
    try! client.sendData(data) // And give them the same result every time! :P
})
Want to do things synchronously?

No problem, all async functions have a synchronous counterpart.

Handle errors:
// All async functions have an optional error closure
client.sendDataAsync(data, onError: { (error) -> Void in
  print(error)
})

// And synchronous functions throws an error
do {
  try client.sendData(data)
} catch {
  print(error)
}

Requirements

Xcode 7 (Swift 2)

Installation

Swocket is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod "Swocket", "~> 0.1.0"

Documentation

Documentation is available at cocoadocs: Swocket documenation

Author

Joakim Gyllström, [email protected]

License

Swocket is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "Swocket",
    "version": "0.1.0",
    "summary": "Asynchronous network framework in Swift",
    "homepage": "https://github.com/mikaoj/Swocket",
    "license": "MIT",
    "authors": {
        "Joakim Gyllstru00f6m": "[email protected]"
    },
    "source": {
        "git": "https://github.com/mikaoj/Swocket.git",
        "tag": "0.1.0"
    },
    "platforms": {
        "ios": "8.0",
        "osx": "10.9"
    },
    "requires_arc": true,
    "source_files": "Pod/**/*"
}

Pin It on Pinterest

Share This