[][src]Crate susyp2p_websocket

Implementation of the susyp2p Transport trait for Websockets.

See the documentation of swarm and of susyp2p in general to learn how to use the Transport trait.

This library is used in a different way depending on whether you are compiling for emscripten or for a different operating system.


On emscripten, you can create a BrowserWsConfig object with BrowserWsConfig::new(). It can then be used as a transport.

Listening on a websockets multiaddress isn't supported on emscripten. Dialing a multiaddress which uses ws on top of TCP/IP will automatically use the XMLHttpRequest Javascript object.

This example is not tested
use susyp2p_websocket::BrowserWsConfig;

let ws_config = BrowserWsConfig::new();
// let _ = ws_config.dial("/ip4/".parse().unwrap());

Other operating systems

On other operating systems, this library doesn't open any socket by itself. Instead it must be plugged on top of another implementation of Transport such as TCP/IP.

This underlying transport must be put inside a WsConfig object through the WsConfig::new() function.

extern crate susyp2p_core;
extern crate susyp2p_tcp;
extern crate susyp2p_websocket;

use susyp2p_core::{Multiaddr, Transport};
use susyp2p_tcp::TcpConfig;
use susyp2p_websocket::WsConfig;

let ws_config = WsConfig::new(TcpConfig::new());
let _ = ws_config.dial("/ip4/".parse().unwrap());



Represents the configuration for a websocket transport capability for susyp2p. Must be put on top of another Transport.