pub struct StreamClient { /* private fields */ }Expand description
Low-level stream client
This is a re-export of aerox_client::StreamClient for users who need
fine-grained control over message handling.
§Example
ⓘ
use aerox::StreamClient;
#[tokio::main]
async fn main() -> aerox::Result<()> {
let mut client = StreamClient::connect("127.0.0.1:8080").await?;
// Manual send/receive loop
client.send_message(1001, &msg).await?;
let (msg_id, response) = client.recv_message::<Response>().await?;
client.close().await?;
Ok(())
}Stream-based client
Provides manual control over message operations. Users explicitly call send/receive methods.
Implementations§
Source§impl StreamClient
impl StreamClient
Sourcepub async fn connect(addr: SocketAddr) -> Result<StreamClient, ClientError>
pub async fn connect(addr: SocketAddr) -> Result<StreamClient, ClientError>
Connect to server
Sourcepub async fn connect_with_config(
config: ClientConfig,
) -> Result<StreamClient, ClientError>
pub async fn connect_with_config( config: ClientConfig, ) -> Result<StreamClient, ClientError>
Connect with custom configuration
Sourcepub async fn send_frame(&mut self, frame: Frame) -> Result<(), ClientError>
pub async fn send_frame(&mut self, frame: Frame) -> Result<(), ClientError>
Send raw frame
Sourcepub async fn send_message<M>(
&mut self,
msg_id: u16,
message: &M,
) -> Result<(), ClientError>where
M: Message,
pub async fn send_message<M>(
&mut self,
msg_id: u16,
message: &M,
) -> Result<(), ClientError>where
M: Message,
Send protobuf message
Sourcepub async fn recv_frame(&mut self) -> Result<Frame, ClientError>
pub async fn recv_frame(&mut self) -> Result<Frame, ClientError>
Receive next frame (blocking)
Sourcepub async fn recv_message<M>(&mut self) -> Result<(u16, M), ClientError>
pub async fn recv_message<M>(&mut self) -> Result<(u16, M), ClientError>
Receive and decode protobuf message
Sourcepub async fn state(&self) -> ClientState
pub async fn state(&self) -> ClientState
Get connection state
Sourcepub async fn is_connected(&self) -> bool
pub async fn is_connected(&self) -> bool
Check if connected
Sourcepub fn server_addr(&self) -> SocketAddr
pub fn server_addr(&self) -> SocketAddr
Get server address
Sourcepub async fn close(self) -> Result<(), ClientError>
pub async fn close(self) -> Result<(), ClientError>
Close connection
Sourcepub fn connection(&mut self) -> &mut ClientConnection
pub fn connection(&mut self) -> &mut ClientConnection
Get connection reference (for advanced usage)
Auto Trait Implementations§
impl Freeze for StreamClient
impl !RefUnwindSafe for StreamClient
impl Send for StreamClient
impl Sync for StreamClient
impl Unpin for StreamClient
impl !UnwindSafe for StreamClient
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
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.