Struct holochain_websocket::WebsocketListener
source · pub struct WebsocketListener { /* private fields */ }
Expand description
A Holochain websocket listener.
Implementations§
source§impl WebsocketListener
impl WebsocketListener
sourcepub async fn bind(
config: Arc<WebsocketConfig>,
addr: impl ToSocketAddrs
) -> Result<Self>
pub async fn bind( config: Arc<WebsocketConfig>, addr: impl ToSocketAddrs ) -> Result<Self>
Bind a new websocket listener.
sourcepub async fn dual_bind(
config: Arc<WebsocketConfig>,
addr_v4: SocketAddrV4,
addr_v6: SocketAddrV6
) -> Result<Self>
pub async fn dual_bind( config: Arc<WebsocketConfig>, addr_v4: SocketAddrV4, addr_v6: SocketAddrV6 ) -> Result<Self>
Bind a new websocket listener on the same port using a v4 and a v6 socket.
If the port is 0, then the OS will be allowed to pick a port for IPv6. This function will then try to bind to the same port for IPv4. If the OS picks a port that is not available for IPv4, then the function will retry binding IPv6 to get a new port and see if that is available for IPv4. If this fails after 5 retries, then an error will be returned.
If either IPv4 or IPv6 is disabled, then the function will fall back to binding to the available stack. An info message will be logged to let the user know that one interface was unavailable, but this is likely intentional or expected in the user’s environment, so it will not be treated as an error that should prevent the listener from starting.
Note: The interface fallback behaviour can be tested manually on Linux by running:
echo 1 | sudo tee /proc/sys/net/ipv6/conf/lo/disable_ipv6
and then trying to start Holochain with info logging enabled. You can undo the change with:
echo 0 | sudo tee /proc/sys/net/ipv6/conf/lo/disable_ipv6
.
sourcepub fn local_addrs(&self) -> Result<Vec<SocketAddr>>
pub fn local_addrs(&self) -> Result<Vec<SocketAddr>>
Get the bound local address of this listener.
sourcepub async fn accept(&self) -> Result<(WebsocketSender, WebsocketReceiver)>
pub async fn accept(&self) -> Result<(WebsocketSender, WebsocketReceiver)>
Accept an incoming connection.