Latest 1.0.0
Homepage https://github.com/Meniny/Socketing
License MIT
Platforms ios 8.0, osx 10.9
Authors

A minimal iOS/macOS Socket Framework.

Requirements

  • iOS 8.0+
  • macOS 10.9+
  • Xcode 8 with Swift 3

Installnation

CocoaPods

pod 'Socketing'

Usage

Use TCP for example:

Client

let client = TCPClient(address: "127.0.0.1", port: 8080)
// or:
let client = TCP.Client(address: "127.0.0.1", port: 8080)
switch client.connect(timeout: 10) {
  case .success:
    // ...
  case .failure(let error):
    // ...
}
let data: Data = // ...
let result = client.send(data: data)
// or:
let result = client.send(string: "string")
// [Int8]?
var data = client.read(length: 1024*10)
client.close()

Server

let server = TCPServer(address: "127.0.0.1", port: 8080)
// or:
let server = TCP.Server(address: "127.0.0.1", port: 8080)
switch server.listen() {
  case .success:
    // ...
  case .failure(let error):
    // ...
}
if let client = server.accept() {
  // ...
}
server.close()

Example:

Client

let client = TCP.Client(address: "127.0.0.1", port: 8080)
switch client.connect(timeout: 60) {
  case .success:
    switch client.send(string: "This is a Message" ) {
      case .success:
        guard let data = client.read(length: 1024 * 10) else {
          // ... goes wrong
          return
        }
        if let response = String(bytes: data, encoding: .utf8) {
          // ... sent
        }
      case .failure(let error):
        // ... sending error
    }
  case .failure(let error):
    // ... connect error
}

Server

let server = TCP.Server(address: "127.0.0.1", port: 8080)

switch server.listen() {
  case .success:
    if let client = server.accept() {
      // ... new client
    }
  case .failure(let error):
    // ... listen error
}

Latest podspec

{
    "name": "Socketing",
    "version": "1.0.0",
    "summary": "A minimal iOS/macOS Socket Framework.",
    "description": "A minimal iOS/macOS Socket Framework in Swift.",
    "homepage": "https://github.com/Meniny/Socketing",
    "license": "MIT",
    "authors": {
        "Meniny": "[email protected]"
    },
    "source": {
        "git": "https://github.com/Meniny/Socketing.git",
        "tag": "1.0.0"
    },
    "social_media_url": "http://meniny.cn/",
    "platforms": {
        "ios": "8.0",
        "osx": "10.9"
    },
    "pod_target_xcconfig": {
        "SWIFT_VERSION": "3.0"
    },
    "source_files": [
        "Socketing/**/*{.swift}",
        "Socketing/**/*{.h}",
        "Socketing/**/*{.c}"
    ],
    "public_header_files": "Socketing/**/*{.h}",
    "ios": {
        "frameworks": "Foundation"
    },
    "osx": {
        "frameworks": "Foundation"
    },
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This