pub struct WebSocket<F>where
F: Factory,{
pub poll: Poll,
pub handler: Handler<F>,
}
Expand description
The WebSocket struct. A WebSocket can support multiple incoming and outgoing connections.
Fields§
§poll: Poll
§handler: Handler<F>
Implementations§
Source§impl<F> WebSocket<F>where
F: Factory,
impl<F> WebSocket<F>where
F: Factory,
Sourcepub fn new(factory: F) -> Result<WebSocket<F>>
pub fn new(factory: F) -> Result<WebSocket<F>>
Create a new WebSocket using the given Factory to create handlers.
Sourcepub fn bind<A>(self, addr_spec: A) -> Result<WebSocket<F>>where
A: ToSocketAddrs,
pub fn bind<A>(self, addr_spec: A) -> Result<WebSocket<F>>where
A: ToSocketAddrs,
Consume the WebSocket and bind to the specified address.
If the addr_spec
yields multiple addresses this will return after the
first successful bind. local_addr
can be called to determine which
address it ended up binding to.
After the server is successfully bound you should start it using run
.
Sourcepub fn listen<A>(self, addr_spec: A) -> Result<WebSocket<F>>where
A: ToSocketAddrs,
pub fn listen<A>(self, addr_spec: A) -> Result<WebSocket<F>>where
A: ToSocketAddrs,
Consume the WebSocket and listen for new connections on the specified address.
§Safety
This method will block until the event loop finishes running.
Sourcepub fn connect(&mut self, url: Url) -> Result<&mut WebSocket<F>>
pub fn connect(&mut self, url: Url) -> Result<&mut WebSocket<F>>
Queue an outgoing connection on this WebSocket. This method may be called multiple times,
but the actual connections will not be established until run
is called.
Sourcepub fn run(self) -> Result<WebSocket<F>>
pub fn run(self) -> Result<WebSocket<F>>
Run the WebSocket. This will run the encapsulated event loop blocking the calling thread until the WebSocket is shutdown.
Sourcepub fn broadcaster(&self) -> Sender
pub fn broadcaster(&self) -> Sender
Get a Sender that can be used to send messages on all connections.
Calling send
on this Sender is equivalent to calling broadcast
.
Calling shutdown
on this Sender will shutdown the WebSocket even if no connections have
been established.
Sourcepub fn local_addr(&self) -> Result<SocketAddr>
pub fn local_addr(&self) -> Result<SocketAddr>
Get the local socket address this socket is bound to. Will return an error
if the backend returns an error. Will return a NotFound
error if
this WebSocket is not a listening socket.