Swiftpack.co - Package - Vinz1911/FastSocket


FastSocket
FastSocket

FastSocket is a proprietary bi-directional message based communication protocol on top of TCP (optionally over other layers in the future). The idea behind this project was, to create a TCP communication like the WebSocket Protocol with less overhead and the ability to track every 8192 bytes read or written on the socket without waiting for the whole message to be transmitted. This allows it to use it as protocol for speed tests for measuring the TCP throughput performance. Our server-sided implementation is written in golang and it's optimized for maximum speed and performance.

Features:

  • [X] send and receive text and data messages
  • [X] async, non-blocking & very fast
  • [X] threading is handled by the framework itself
  • [X] track every 8192 send & received bytes
  • [X] allows you to chose the network interface!
  • [X] zer0 dependencies, native swift implementation with Network.framework
  • [X] custom error management
  • [X] all errors are routed through the error closure
  • [X] maximum frame size 16777216 bytes (with overhead)
  • [X] content length base framing instead of fin byte termination
  • [X] send/receive multiple messages at once (currently only in debug mode)
  • [X] TLS support

License:

License

Swift Version:

Swift 5

Build Status:

| Branch | Build Status | Coverage | Maintainability | |:-------:|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|:---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:| | master | Travis Master | Code Climate Coverage | Code Climate Maintainability | | develop | Travis Develop | | |

Installation:

CocoaPods

Add the following line to your Podfile:

pod 'FastSocket', :git => 'https://github.com/Vinz1911/FastSocket.git'

Carthage

Add the following line to your Cartfile

github "Vinz1911/FastSocket"

Import:

// import the Framework
import FastSocket
// normal init with TCP (unsecure) transfer type
let socket = FastSocket(host: "example.com", port: 8080)
// enhanced init with the ability to set TLS (secure) as transfer type
let socket = FastSocket(host: "example.com", port: 443, type: .tls)

Closures:

socket.on.ready = {
    // this is called after the connection
    // was successfully established and is ready
}
socket.on.message = { message in
    // this is called everytime
    // a message was received
}
socket.on.bytes = { count in
    // this is called every 8192 bytes
    // are readed from the socket
}
socket.on.close = {
    // this is called after
    // the socket was closed
}
socket.on.error = { error in
    // this is called everytime
    // an error appeared
}

Cast Messages:

socket.on.message = { message in
    // it's only possible to cast messages
    // as Data or as String
    if case let message as Data = message {
        // cast message as data
        print("Data count: \(message.count)")
    }
    if case let message as String = message {
        // cast message as string
        print("Message: \(message)")
    }
}

Read Bytes Count:

socket.on.bytes = { bytes in
    // input bytes are the ones, which are
    // readed from the socket, this function
    // returns the byte count
    if case .input(let count) = bytes {
        print("Bytes count: \(count)")
    }
    // output bytes are the ones, which are
    // written on the socket, this function
    // returns the byte count
    if case .output(let count) = bytes {
        print("Bytes count: \(count)")
    }
}

Connect:

// try to connect to the host
// timeout after 5.0 seconds
socket.connect()

Disconnect:

// closes the connection
socket.disconnect()

Send Messages:

// the send func is a generic func
// it allows to send `String` and `Data`
socket.send(message: T)

Additional Parameters:

// FastSocket was build in top of Apple's Network.framework
// that allows us to use lot of TCP features like fast open or
// to select the network interface type

// set the traffics service class
socket.parameters.serviceClass = .interactiveVoice

// enable fast open
socket.parameters.allowFastOpen = true

// select the interface type
// if it's not available, it will cancel with an error
socket.parameters.requiredInterfaceType = .cellular

Authors:

Vinzenz Weist Juan Romero

Github

link
Stars: 2
Help us keep the lights on

Dependencies

Used By

Total: 0

Releases

2.0.0 - Sep 19, 2019

  • updated framing protocol
  • cleanup code
  • improved stability
  • removed untrusted tls
  • iOS 13+ support
  • preparation for .xcframework and swift 5.1

Note: previous versions are not compatible with the backend anymore

1.1.0 - May 26, 2019

  • cleanup
  • removed unnecessary self
  • renaming of transportParameters to the original naming convention of parameters

1.0.1 - May 18, 2019

  • callback for reading transmitted bytes count was inaccessible due to wrong access level, this should be fixed now

1.0.0 - May 18, 2019

  • first public release of the FastSocket framework
  • stabilized all features
  • new framing process
  • fast as hell, tested on 10GE Back to Back
  • TLS support with untrusted certificates
  • more generic codebase

0.5.0 - May 7, 2019

This is our initial release with the basic feature set:

  • send and receive text and data messages
  • async, non-blocking & very fast
  • threading is handled by the framework itself
  • track every 8192 send & received bytes
  • allows you to chose the network interface!
  • zero dependencies, native swift implementation with Network.framework
  • custom error management
  • all errors are routed through the error closure
  • maximum frame size 16777216 bytes (with overhead)