Type Alias WsConfig

Source
pub type WsConfig<Transport> = Config<Transport>;
👎Deprecated: Use Config instead
Available on crate feature websocket and non-WebAssembly only.
Expand description

A Websocket transport.

DO NOT wrap this transport with a DNS transport if you want Secure Websockets to work.

A Secure Websocket transport needs to wrap DNS transport to resolve domain names after they are checked against the remote certificates. Use a combination of DNS and TCP transports to build a Secure Websocket transport.

If you don’t need Secure Websocket’s support, use a plain TCP transport as an inner transport.

§Dependencies

This transport requires the zlib shared library to be installed on the system.

Future releases might lift this requirement, see https://github.com/paritytech/soketto/issues/72.

§Examples

Secure Websocket transport:


let mut transport = websocket::Config::new(
    dns::async_std::Transport::system(tcp::async_io::Transport::new(tcp::Config::default()))
        .await
        .unwrap(),
);

let rcgen_cert = generate_simple_self_signed(vec!["localhost".to_string()]).unwrap();
let priv_key = websocket::tls::PrivateKey::new(rcgen_cert.serialize_private_key_der());
let cert = websocket::tls::Certificate::new(rcgen_cert.serialize_der().unwrap());
transport.set_tls_config(websocket::tls::Config::new(priv_key, vec![cert]).unwrap());

let id = transport
    .listen_on(
        ListenerId::next(),
        "/ip4/127.0.0.1/tcp/0/tls/ws".parse().unwrap(),
    )
    .unwrap();

let addr = future::poll_fn(|cx| Pin::new(&mut transport).poll(cx))
    .await
    .into_new_address()
    .unwrap();
println!("Listening on {addr}");

Plain Websocket transport:


let mut transport =
    websocket::Config::new(tcp::async_io::Transport::new(tcp::Config::default()));

let id = transport
    .listen_on(
        ListenerId::next(),
        "/ip4/127.0.0.1/tcp/0/ws".parse().unwrap(),
    )
    .unwrap();

let addr = future::poll_fn(|cx| Pin::new(&mut transport).poll(cx))
    .await
    .into_new_address()
    .unwrap();
println!("Listening on {addr}");

Aliased Type§

struct WsConfig<Transport> { /* private fields */ }