[][src]Struct libzmq::Server

pub struct Server { /* fields omitted */ }

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

CharacteristicValue
Compatible peer socketsServer
DirectionBidirectional
PatternUnrestricted
Incoming routing strategyFair-queued
Outgoing routing strategySee text
Action in mute stateBlock

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]

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]

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]

impl PartialEq<Server> for Server[src]

impl RecvMsg for Server[src]

impl Send for Server[src]

impl SendMsg for Server[src]

impl Socket for Server[src]

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]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,