GithubHelp home page GithubHelp logo

fbion / swiftdssocket Goto Github PK

View Code? Open in Web Editor NEW

This project forked from csujedihy/swiftdssocket

0.0 1.0 0.0 568 KB

DispatchSource based socket framework written in pure Swift

License: MIT License

Swift 98.90% Ruby 1.10%

swiftdssocket's Introduction

Travis-CI macOS iOS Swift Version CocoaPods Carthage Compatible SwiftPM Compatible

SwiftDSSocket

Overview

SwiftDSSocket is a purely swift based asynchronous socket framework built atop DispatchSource. Function signatures are pretty much similar to those in CocoaAsyncSocket because I implemented this framework by learning the source code of CocoaAsyncSocket. The initial idea to build this farmework is driven by the need of network library to communicate with KEXT (NKE) to re-write my Proximac project but none of frameworks I found in github supports that. Thus, I decided to implemented my own framework to do so.

Note: This framework is still under active development. It only passes my unit tests and might have various bugs.

Features

Full Delegate Support

  • every operation invokes a call to your delagate method.

IPv6 Support

  • listens only on IPv6 protocol but accepts both IPv4 and IPv6 incoming connections.
  • conforms to Apple's new App Store restriction on IPv6 only environment with NAT64/DNS64.

DNS Enabled

  • takes advantage of sythesized IPv6 address introduced in iOS 9 and OS X 10.11 for better IPv6 support.
  • uses GCD to do DNS concurrently and connect to the first reachable address.

KEXT Bi-directional Interaction

  • takes a bundle ID to interact with your KEXT like TCP stream.

Using SwiftDSSocket

Including in your project

Swift Package Manager

To include SwiftDSSocket into a Swift Package Manager package, add it to the dependencies attribute defined in your Package.swift file. For example:

    dependencies: [
        .Package(url: "https://github.com/csujedihy/SwiftDSSocket", "x.x.x")
    ]

CocoaPods

To include SwiftDSSocket in a project using CocoaPods, you just add SwiftDSSocket to your Podfile, for example:

    target 'MyApp' do
        use_frameworks!
        pod 'SwiftDSSocket'
    end

Carthage

To include SwiftDSSocket in a project using Carthage, add a line to your Cartfile with the GitHub organization and project names and version. For example:

    github "csujedihy/SwiftDSSocket"

Documentation

https://csujedihy.github.io/SwiftDSSocket/

Example:

The following example creates a default SwiftDSSocket instance and then immediately starts listening on port 9999 and echoes back everything sent to this server.

You can simply use telnet 127.0.0.1 9999 to connect to this server and send whatever you want.

import Cocoa
import SwiftDSSocket

class ViewController: NSViewController {
  var server: SwiftDSSocket?
  var newClient: SwiftDSSocket?
  let ServerTag = 0
  
  override func viewDidLoad() {
    super.viewDidLoad()
    server = SwiftDSSocket(delegate: self, delegateQueue: .main, type: .tcp)
    try? server?.accept(onPort: 9999)
  }
}


extension ViewController: SwiftDSSocketDelegate {
  func socket(sock: SwiftDSSocket, didAcceptNewSocket newSocket: SwiftDSSocket) {
    newClient = newSocket
    newSocket.readData(tag: ServerTag)
  }
  
  func socket(sock: SwiftDSSocket, didRead data: Data, tag: Int) {
    sock.write(data: data, tag: ServerTag)
    sock.readData(tag: ServerTag)
  }
}

Tips: Check out Demo folder to see more examples for different environments.

swiftdssocket's People

Contributors

csujedihy avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.