[−][src]Struct libzmq::Server
A Server
socket is a socket used for advanced request-reply messaging.
A Server
socket talks to a set of Client
sockets. The Client
must
first initiate the conversation, which generates a routing_id
associated
with the connection. Each message received from a Server
will have this
routing_id
. To send messages back to the server, you must associate them
to a RoutingId
either manually using set_routing_id
or via the route
convenience method. If the routing_id
is not specified, or
does not refer to a connected server peer, the send call will fail with
HostUnreachable
.
Mute State
When a Server
socket enters the mute state due to having reached the high
water mark for all servers, or if there are no servers at
all, then any send
operations on the socket shall block until the mute
state ends or at least one downstream node becomes available for sending;
messages are not discarded.
Summary of Characteristics
Characteristic | Value |
---|---|
Compatible peer sockets | Server |
Direction | Bidirectional |
Pattern | Unrestricted |
Incoming routing strategy | Fair-queued |
Outgoing routing strategy | See text |
Action in mute state | Block |
Example
use libzmq::{prelude::*, *}; let addr: TcpAddr = "127.0.0.1:*".try_into()?; let server = ServerBuilder::new() .bind(addr) .build()?; let bound = server.last_endpoint()?; let client = ClientBuilder::new() .connect(bound) .build()?; // The client initiates the conversation so it is assigned a `routing_id`. client.send("request")?; let msg = server.recv_msg()?; assert_eq!("request", msg.to_str()?); let id = msg.routing_id().unwrap(); // Using this `routing_id`, we can now route as many replies as we // want to the client. server.route("reply 1", id)?; server.route("reply 2", id)?; // The `routing_id` is discarted when the message is sent to the client. let mut msg = client.recv_msg()?; assert_eq!("reply 1", msg.to_str()?); assert!(msg.routing_id().is_none()); client.recv(&mut msg)?; assert_eq!("reply 2", msg.to_str()?); assert!(msg.routing_id().is_none());
Implementations
impl Server
[src]
pub fn new() -> Result<Self, Error>
[src]
pub fn with_ctx(handle: CtxHandle) -> Result<Server, Error>
[src]
Create a Server
socket associated with a specific context
from a CtxHandle
.
Returned Error Variants
pub fn ctx(&self) -> CtxHandle
[src]
Returns a reference to the context of the socket.
pub fn route<M>(&self, msg: M, id: RoutingId) -> Result<(), Error<Msg>> where
M: Into<Msg>,
[src]
M: Into<Msg>,
Push a message into the outgoing socket queue with the specified
RoutingId
.
This is a convenience function that sets the Msg
's RoutingId
then
sends it.
See send
for more information.
pub fn try_route<M>(&self, msg: M, id: RoutingId) -> Result<(), Error<Msg>> where
M: Into<Msg>,
[src]
M: Into<Msg>,
Try to push a message into the outgoing socket queue with the specified
RoutingId
.
This is a convenience function that sets the Msg
's RoutingId
then
tries sends it.
See try_send
for more information.
Trait Implementations
impl Clone for Server
[src]
impl Debug for Server
[src]
impl Eq for Server
[src]
impl<'a> From<&'a Server> for Pollable<'a>
[src]
impl Heartbeating for Server
[src]
fn heartbeat(&self) -> Option<Heartbeat>
[src]
fn set_heartbeat(&self, maybe: Option<Heartbeat>) -> Result<(), Error>
[src]
impl PartialEq<Server> for Server
[src]
impl RecvMsg for Server
[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 Server
[src]
impl SendMsg for Server
[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 Server
[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 Server
[src]
impl StructuralPartialEq for Server
[src]
impl Sync for Server
[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>,