Rainway Network

Rainway Network

The Rainway Network is how apps using Rainway find each other.

Each entity connected to the network is a Peer, identified by its Rainway Peer ID.

Peers on the Rainway Network exchange connection requests and session information in order to establish a peer-to-peer connection. Once a connection between Peers has been established, they no longer use the Rainway Network to communicate.

First steps

Connecting to the Rainway Network happens automatically when you call RainwaySDK.ConnectAsync. The only property you're required to pass is ApiKey.

using Rainway.SDK;
using Rainway.SDK.Options;

var conn = await RainwaySDK.ConnectAsync(new ConnectOptions() { ApiKey = "pk_XXXXX" });

The resulting Task resolves to a RainwayConnection instance that can be used to connect or handle requests to connect from other peers. It's time to get connected peer-to-peer!

Peer IDs

The first time Rainway is initialized on a device, it generates and stores a Peer ID. This is a 63-bit number that uniquely identifies the device on the Rainway Network.

To connect your device to another over Rainway, you must know the other's Peer ID. A device's Peer ID is exposed through the Id property on RainwayConnection.

var peerId = conn.Id;

How you store Peer IDs will vary depending on how your application uses Rainway. For example, you could store them in your application database to let Peers know about each other.

Connecting to a Peer

Once you have a Peer's ID, you can call connect to establish the connection:

var peer = await conn.ConnectAsync(new PeerConnectOptions() { Id = remotePeerId });

This task will resolve once the Peer has accepted your connection request.

To test against the example web app, try running it on another device, and connecting from your web app to its Peer ID.


Did this page help you?