pub struct TcpClient { /* private fields */ }
Expand description
The TcpClient
struct represents a TCP client with a stream
field of type TcpStream
.
§Properties:
stream
: Thestream
property in theTcpClient
struct represents the TCP stream that is used for communication with the server. It allows data to be sent and received over the network connection.
Implementations§
Source§impl TcpClient
impl TcpClient
Sourcepub async fn connect(addr: &str) -> Result<Self, Box<dyn Error>>
pub async fn connect(addr: &str) -> Result<Self, Box<dyn Error>>
The function connect
establishes a TCP connection to the specified address asynchronously in
Rust.
§Arguments:
addr
: Theaddr
parameter in theconnect
function is a reference to a string (&str
) which represents the address to which the TCP client will connect. This address typically includes the IP address and port number of the server to establish the connection with.
§Returns:
The connect
function is returning a Result
containing either an instance of TcpClient
if
the connection is successful, or a boxed Error
trait object if an error occurs during the
connection process.
Sourcepub async fn send_message(
&mut self,
message: &str,
) -> Result<(), Box<dyn Error>>
pub async fn send_message( &mut self, message: &str, ) -> Result<(), Box<dyn Error>>
The function send_message
sends a message over a stream in Rust asynchronously.
§Arguments:
message
: Themessage
parameter in thesend_message
function is a reference to a string (&str
) that represents the message to be sent.
§Returns:
The send_message
function returns a Result
enum with the success type ()
(unit type) if
the message is successfully sent, or an error wrapped in a Box<dyn Error>
if an error occurs
during the process.
Auto Trait Implementations§
impl !Freeze for TcpClient
impl RefUnwindSafe for TcpClient
impl Send for TcpClient
impl Sync for TcpClient
impl Unpin for TcpClient
impl UnwindSafe for TcpClient
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