Tunneling Mozilla WebThings Gateway through NKN client

Mozilla webthings banner

NKN client can be used to transparently tunnel any TCP based application in a purely decentralized way, and the application itself does not need any modification. Such tunnel does not require any side to have public IP address or port forwarding, and no centralized server is needed at all. Below is an instruction for Mozilla WebThings Gateway.

Both the client (user) and server (gateway) side needs to run nkn-tunnel. On the gateway device (or any device in the same local network), we start nkn-tunnel in server mode:

./nkn-tunnel -from nkn -to -s <seed>

Where is the WebThings Gateway web server address, and <seed> is the secret seed (similar to private key) used to create NKN client. The seed should be a 64-char hex string. If seed is omitted, a random seed will be used.

After nkn-tunnel is started, it will print out the listening address:

Listening at <server-listening-address>

where <server-listening-address> is the NKN address of the tunnel.

Then on the user side, we start nkn-tunnel in client mode:

./nkn-tunnel -from -to <server-listening-address>

Now user can access the gateway interface by visiting

Embed nkn-tunnel in iOS/Android application

nkn-tunnel is written in Go and can be compiled to a native iOS/Android library using Go mobile.

Below is a simple iOS application that use nkn-tunnel + WebView as a minimal WebThings Gateway mobile client.


Using NKN client as p2p communication layer

nkn-tunnel is the easiest way to integrate with existing application, but might not be the most friendly way to users because it requires client side to run nkn-tunnel also. If you are able and willing to modify the server side application, you can use NKN client as the p2p communication layer and integrate NKN client to both the client and server side of your application. NKN client is currently available in Go, JavaScript, Java.

About Mozilla WebThings

The Web of Things connects real-world objects to the World Wide Web.

The idea of the Web of Things is to create a decentralized Internet of Things by giving things URLs on the web to make them linkable and discoverable, and defining a standard data model and APIs to make them interoperable.

Mozilla WebThings is Mozilla’s open source implementation of the Web of Things, including the WebThings Gateway and the WebThings framework. For more information please check out: