[−][src]Struct libzmq::Client
A Client
socket is used for advanced request-reply messaging.
Client
sockets are threadsafe and can be used from multiple threads at the
same time. Note that replies from a Server
socket will go to the first
client thread that calls recv
. If you need to get replies back to the
originating thread, use one Client
socket per thread.
When a Client
socket is connected to multiple sockets, outgoing
messages are distributed between connected peers on a round-robin basis.
Likewise, the Client
socket receives messages fairly from each connected peer.
Mute State
When Client
socket enters the mute state due to having reached the high water
mark, or if there are no peers at all, then any send operations on the
socket shall block until the mute state ends or at least one peer becomes
available for sending; messages are not discarded.
Summary of Characteristics
Characteristic | Value |
---|---|
Compatible peer sockets | Server |
Direction | Bidirectional |
Send/receive pattern | Unrestricted |
Outgoing routing strategy | Round-robin |
Incoming routing strategy | Fair-queued |
Action in mute state | Block |
Example
use libzmq::{prelude::*, *}; // Use a system assigned port. let addr: TcpAddr = "127.0.0.1:*".try_into()?; let server = ServerBuilder::new() .bind(addr) .build()?; // Retrieve the addr that was assigned. let bound = server.last_endpoint()?; let client = ClientBuilder::new() .connect(bound) .build()?; // Send a string request. client.send("tell me something")?; // Receive the client request. let msg = server.recv_msg()?; let id = msg.routing_id().unwrap(); // Reply to the client. server.route("it takes 224 bits to store a i32 in java", id)?; // We send as much replies as we want. server.route("also don't talk to me", id)?; // Retreive the first reply. let mut msg = client.recv_msg()?; // And the second. client.recv(&mut msg)?;
Implementations
impl Client
[src]
pub fn new() -> Result<Self, Error>
[src]
pub fn with_ctx(handle: CtxHandle) -> Result<Self, Error>
[src]
Create a Client
socket associated with a specific context
from a CtxHandle
.
Returned Error Variants
pub fn ctx(&self) -> CtxHandle
[src]
Returns the handle to the Ctx
of the socket.
Trait Implementations
impl Clone for Client
[src]
impl Debug for Client
[src]
impl Eq for Client
[src]
impl<'a> From<&'a Client> for Pollable<'a>
[src]
impl Heartbeating for Client
[src]
fn heartbeat(&self) -> Option<Heartbeat>
[src]
fn set_heartbeat(&self, maybe: Option<Heartbeat>) -> Result<(), Error>
[src]
impl PartialEq<Client> for Client
[src]
impl RecvMsg for Client
[src]
fn recv(&self, msg: &mut Msg) -> Result<(), Error>
[src]
fn try_recv(&self, msg: &mut Msg) -> Result<(), Error>
[src]
fn recv_msg(&self) -> Result<Msg, Error>
[src]
fn try_recv_msg(&self) -> Result<Msg, Error>
[src]
fn recv_hwm(&self) -> Result<i32, Error>
[src]
fn set_recv_hwm(&self, hwm: i32) -> Result<(), Error>
[src]
fn recv_timeout(&self) -> Result<Period, Error>
[src]
fn set_recv_timeout<P>(&self, period: P) -> Result<(), Error> where
P: Into<Period>,
[src]
P: Into<Period>,
impl Send for Client
[src]
impl SendMsg for Client
[src]
fn send<M>(&self, msg: M) -> Result<(), Error<Msg>> where
M: Into<Msg>,
[src]
M: Into<Msg>,
fn try_send<M>(&self, msg: M) -> Result<(), Error<Msg>> where
M: Into<Msg>,
[src]
M: Into<Msg>,
fn send_hwm(&self) -> Result<i32, Error>
[src]
fn set_send_hwm(&self, hwm: i32) -> Result<(), Error>
[src]
fn send_timeout(&self) -> Result<Period, Error>
[src]
fn set_send_timeout<P>(&self, period: P) -> Result<(), Error> where
P: Into<Period>,
[src]
P: Into<Period>,
impl Socket for Client
[src]
fn connect<E>(&self, endpoint: E) -> Result<(), Error> where
E: Into<Endpoint>,
[src]
E: Into<Endpoint>,
fn bind<E>(&self, endpoint: E) -> Result<(), Error> where
E: Into<Endpoint>,
[src]
E: Into<Endpoint>,
fn disconnect<E>(&self, endpoint: E) -> Result<(), Error> where
E: Into<Endpoint>,
[src]
E: Into<Endpoint>,
fn unbind<I, E>(&self, endpoint: E) -> Result<(), Error> where
E: Into<Endpoint>,
[src]
E: Into<Endpoint>,
fn last_endpoint(&self) -> Result<Endpoint, Error>
[src]
fn mechanism(&self) -> Mechanism
[src]
fn set_mechanism<M>(&self, mechanism: M) -> Result<(), Error> where
M: Into<Mechanism>,
[src]
M: Into<Mechanism>,
impl StructuralEq for Client
[src]
impl StructuralPartialEq for Client
[src]
impl Sync for Client
[src]
Auto Trait Implementations
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,