SocketKit 0.2

SocketKit 0.2

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Sep 2016
SPMSupports SPM

Maintained by Yaxin Cheng.



  • By
  • Yaxin Cheng

SocketKit

A wrapped Swift toolkit for socket connection

Requirements:

  • Xcode 8.0+
  • iOS 10.0+
  • Swift 3.0+

Installation:

SocketKit can be installed through Cocoapods or manual import.

User Manual:

Kit imports

import SocketKit

Socket.swift

The only class will be used in the kit. All the requests go from this kit.

Constructor

public init(address: String, port: Int) throws { ... }

SocketError.connectionFailed may be thrown from the constructor when connection failed

Read from socket

public func read(complete: @escaping (String?) -> Void) throws { ... }

This function accepts a call back closure, which will be called when value is read from socket server side
The closure accepts an optional string, and may throw out a SocketError.notConnected if the socket lost connection

Write to socket

public func write(value: String) throws { ... }

This function accepts an UTF-8 string value, and encode the string to binary data, then write to the socket server.
SocketError.notConnected may be thrown if the socket connection is lost
SocketError.notWritable may be thrown if the socket is not allowed to write values
SocketError.dataEncodingFailed may be thrown if the string value cannot be encoded

Connection status

public var isConnected: Bool

This attribute returns true if the socket is connected, otherwise false

License

WeatherKit is released under the MIT license. See LICENSE for details.