pub struct Connection { /* private fields */ }Expand description
Represents a WebSocket connection
Implementations§
Source§impl Connection
impl Connection
Sourcepub fn new(remote_addr: SocketAddr, local_addr: SocketAddr) -> Self
pub fn new(remote_addr: SocketAddr, local_addr: SocketAddr) -> Self
Create a new connection
Sourcepub fn with_stream(
remote_addr: SocketAddr,
local_addr: SocketAddr,
stream: Box<dyn TransportStream>,
) -> Self
pub fn with_stream( remote_addr: SocketAddr, local_addr: SocketAddr, stream: Box<dyn TransportStream>, ) -> Self
Create a new connection with a transport stream
Sourcepub fn with_timeout(
remote_addr: SocketAddr,
local_addr: SocketAddr,
stream: Box<dyn TransportStream>,
idle_timeout: Option<Duration>,
) -> Self
pub fn with_timeout( remote_addr: SocketAddr, local_addr: SocketAddr, stream: Box<dyn TransportStream>, idle_timeout: Option<Duration>, ) -> Self
Create a new connection with timeout settings
Sourcepub fn set_stream(&mut self, stream: Box<dyn TransportStream>)
pub fn set_stream(&mut self, stream: Box<dyn TransportStream>)
Set the transport stream
Sourcepub fn remote_addr(&self) -> SocketAddr
pub fn remote_addr(&self) -> SocketAddr
Get the remote address
Sourcepub fn local_addr(&self) -> SocketAddr
pub fn local_addr(&self) -> SocketAddr
Get the local address
Sourcepub fn state(&self) -> ConnectionState
pub fn state(&self) -> ConnectionState
Get the connection state
Sourcepub fn metadata(&self) -> &ConnectionMetadata
pub fn metadata(&self) -> &ConnectionMetadata
Get the connection metadata
Sourcepub fn is_timed_out(&self) -> bool
pub fn is_timed_out(&self) -> bool
Check if the connection has timed out
Sourcepub fn time_until_timeout(&self) -> Option<Duration>
pub fn time_until_timeout(&self) -> Option<Duration>
Get the time until the connection times out
Sourcepub fn set_idle_timeout(&mut self, timeout: Option<Duration>)
pub fn set_idle_timeout(&mut self, timeout: Option<Duration>)
Set the idle timeout
Sourcepub async fn send_binary(&mut self, data: impl Into<Bytes>) -> Result<()>
pub async fn send_binary(&mut self, data: impl Into<Bytes>) -> Result<()>
Send a binary message
Sourcepub async fn close(
&mut self,
code: Option<u16>,
reason: Option<&str>,
) -> Result<()>
pub async fn close( &mut self, code: Option<u16>, reason: Option<&str>, ) -> Result<()>
Close the connection
Sourcepub fn is_connected(&self) -> bool
pub fn is_connected(&self) -> bool
Check if the connection is established
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Connection
impl !RefUnwindSafe for Connection
impl Send for Connection
impl Sync for Connection
impl Unpin for Connection
impl !UnwindSafe for Connection
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more