pub struct Sender { /* private fields */ }
Expand description
A representation of the output of the WebSocket connection. Use this to send messages to the other endpoint.
Implementations
sourceimpl Sender
impl Sender
sourcepub fn connection_id(&self) -> u32
pub fn connection_id(&self) -> u32
A connection_id identifying this sender within the WebSocket.
sourcepub fn send<M>(&self, msg: M) -> Result<()> where
M: Into<Message>,
pub fn send<M>(&self, msg: M) -> Result<()> where
M: Into<Message>,
Send a message over the connection.
sourcepub fn broadcast<M>(&self, msg: M) -> Result<()> where
M: Into<Message>,
pub fn broadcast<M>(&self, msg: M) -> Result<()> where
M: Into<Message>,
Send a message to the endpoints of all connections.
Be careful with this method. It does not discriminate between client and server connections. If your WebSocket is only functioning as a server, then usage is simple, this method will send a copy of the message to each connected client. However, if you have a WebSocket that is listening for connections and is also connected to another WebSocket, this method will broadcast a copy of the message to all the clients connected and to that WebSocket server.
sourcepub fn close_with_reason<S>(&self, code: CloseCode, reason: S) -> Result<()> where
S: Into<Cow<'static, str>>,
pub fn close_with_reason<S>(&self, code: CloseCode, reason: S) -> Result<()> where
S: Into<Cow<'static, str>>,
Send a close code and provide a descriptive reason for closing.
sourcepub fn ping(&self, data: Vec<u8>) -> Result<()>
pub fn ping(&self, data: Vec<u8>) -> Result<()>
Send a ping to the other endpoint with the given test data.
sourcepub fn pong(&self, data: Vec<u8>) -> Result<()>
pub fn pong(&self, data: Vec<u8>) -> Result<()>
Send a pong to the other endpoint responding with the given test data.
sourcepub fn connect(&self, url: Url) -> Result<()>
pub fn connect(&self, url: Url) -> Result<()>
Queue a new connection on this WebSocket to the specified URL.
sourcepub fn shutdown(&self) -> Result<()>
pub fn shutdown(&self) -> Result<()>
Request that all connections terminate and that the WebSocket stop running.
sourcepub fn timeout(&self, ms: u64, token: Token) -> Result<()>
pub fn timeout(&self, ms: u64, token: Token) -> Result<()>
Schedule a token
to be sent to the WebSocket Handler’s on_timeout
method
after ms
milliseconds
sourcepub fn cancel(&self, timeout: Timeout) -> Result<()>
pub fn cancel(&self, timeout: Timeout) -> Result<()>
Queue the cancellation of a previously scheduled timeout.
This method is not guaranteed to prevent the timeout from occurring, because it is possible to call this method after a timeout has already occurred. It is still necessary to handle spurious timeouts.
Trait Implementations
impl Eq for Sender
Auto Trait Implementations
impl !RefUnwindSafe for Sender
impl Send for Sender
impl Sync for Sender
impl Unpin for Sender
impl !UnwindSafe for Sender
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more