Skip to content

alexjuda/Servus

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Servus

Lightweight wrapper around NSNetService for use in iOS apps. Enables discovering other devices over standard LAN and ad-hoc peer-to-peer WiFi or Bluetooth networks.

Written in Swift 3.

What is it for?

When nearby devices are discovered and properly resolved, Servus provides a hostname for each of them. Combine it with a HTTP Server for iOS, and HTTP requests, and BAM! You send data between devices using Bluetooth or WiFi without having to worry about the infrastructure.

Isn't it MultipeerConnectivity?

Apple provides a framework for such ad-hoc networks. However, from my experience it's quite unreliable (gets stuck pretty often), and is painful to test.

Servus, on the other hand, provides only the discovery phase. Data transfer is done separately, so the developer has greater insight to it. Also, it's super easy to test! Just open the app on the simulator, or on a device within the same LAN as your computer and you can send HTTP requests to http://your-device-hostname:PORT/. And it works. Magic.

Example

explorer = Explorer()
explorer.delegate = self
explorer.startExploring() // Start announcing this device's presence & reporting discovery of other ones.

...

func explorer(explorer: Explorer, didDeterminePeer peer: Peer) {
    print("Determined hostname for \(peer.identifier): \(peer.hostname!)")
}

For working example check out the app target.

Installation

Carthage

Servus can be integrated with Xcode project via Carthage, a dependency manager for Cocoa.

  1. Add github "airalex/Servus" to your Cartfile.
  2. Run carthage update
  3. Drag Carthage/Build/iOS/Servus.framework to your Xcode project, or select File > Add Files...
  4. Make sure /usr/local/bin/carthage copy-frameworks Run Script phase is present for your target.
  5. Add $(SRCROOT)/Carthage/Build/iOS/Servus.framework to Input Files list.

Manual

  1. git clone git@github.com:airalex/Servus.git
  2. Copy Servus/ directory to your project.
  3. Make sure all files are present in your project (Explorer, Peer, Advertiser, Resolver, Revealer).