[][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 set_routing_id on the messages. 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::*, *};
use std::convert::TryInto;

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 routing_id = msg.routing_id().unwrap();

// Using this `routing_id`, we can now route as many replies as we
// want to the client.
let mut msg: Msg = "reply 1".into();
msg.set_routing_id(routing_id);
server.send(msg)?;
let mut msg: Msg = "reply 2".into();
msg.set_routing_id(routing_id);
server.send(msg)?;

// 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());

Methods

impl Server[src]

pub fn new() -> Result<Self, Error>[src]

pub fn with_ctx<C>(ctx: C) -> Result<Server, Error> where
    C: Into<Ctx>, 
[src]

Create a Server socket from a specific context.

Returned Error Variants

pub fn ctx(&self) -> &Ctx[src]

Returns a reference to the context of the socket.

Trait Implementations

impl RecvMsg for Server[src]

fn recv(&self, msg: &mut Msg) -> Result<(), Error>[src]

Retreive a message from the inbound socket queue. Read more

fn try_recv(&self, msg: &mut Msg) -> Result<(), Error>[src]

Try to retrieve a message from the inbound socket queue without blocking. Read more

fn recv_msg(&self) -> Result<Msg, Error>[src]

A convenience function that allocates a [Msg] with the same properties as [recv]. Read more

fn try_recv_msg(&self) -> Result<Msg, Error>[src]

A convenience function that allocates a [Msg] with the same properties as [try_recv]. Read more

fn recv_high_water_mark(&self) -> Result<Option<i32>, Error>[src]

The high water mark for incoming messages on the specified socket. Read more

fn set_recv_high_water_mark(&self, maybe: Option<i32>) -> Result<(), Error>[src]

Set the high water mark for inbound messages on the specified socket. Read more

fn recv_timeout(&self) -> Result<Option<Duration>, Error>[src]

The timeout for [recv] on the socket. Read more

fn set_recv_timeout(&self, maybe: Option<Duration>) -> Result<(), Error>[src]

Sets the timeout for [recv] on the socket. Read more

impl SendMsg for Server[src]

fn send<M>(&self, sendable: M) -> Result<(), Error<Msg>> where
    M: Into<Msg>, 
[src]

Push a message into the outgoing socket queue. Read more

fn try_send<M>(&self, sendable: M) -> Result<(), Error<Msg>> where
    M: Into<Msg>, 
[src]

Try to push a message into the outgoing socket queue without blocking. Read more

fn send_high_water_mark(&self) -> Result<Option<i32>, Error>[src]

The high water mark for outbound messages on the specified socket. Read more

fn set_send_high_water_mark(&self, maybe: Option<i32>) -> Result<(), Error>[src]

Set the high water mark for outbound messages on the specified socket. Read more

fn send_timeout(&self) -> Result<Option<Duration>, Error>[src]

Sets the timeout for [send] on the socket. Read more

fn set_send_timeout(&self, maybe: Option<Duration>) -> Result<(), Error>[src]

Sets the timeout for [send] on the socket. Read more

impl Socket for Server[src]

fn connect<I, E>(&self, endpoints: I) -> Result<(), Error<usize>> where
    I: IntoIterator<Item = E>,
    E: Into<Endpoint>, 
[src]

Schedules a connection to one or more [Endpoints] and then accepts incoming connections. Read more

fn connected(&self) -> Vec<Endpoint>[src]

Returns a snapshot of the list of connected Endpoint. Read more

fn disconnect<I, E>(&self, endpoints: I) -> Result<(), Error<usize>> where
    I: IntoIterator<Item = E>,
    E: Into<Endpoint>, 
[src]

Disconnect the socket from one or more [Endpoints]. Read more

fn bind<I, E>(&self, endpoints: I) -> Result<(), Error<usize>> where
    I: IntoIterator<Item = E>,
    E: Into<Endpoint>, 
[src]

Schedules a bind to one or more [Endpoints] and then accepts incoming connections. Read more

fn bound(&self) -> Vec<Endpoint>[src]

Returns a snapshot of the list of bound Endpoint. Read more

fn unbind<I, E>(&self, endpoints: I) -> Result<(), Error<usize>> where
    I: IntoIterator<Item = E>,
    E: Into<Endpoint>, 
[src]

Unbinds the socket from one or more [Endpoints]. Read more

fn last_endpoint(&self) -> Result<Option<Endpoint>, Error>[src]

Retrieve the last endpoint connected or bound to. Read more

fn backlog(&self) -> Result<i32, Error>[src]

Retrieve the maximum length of the queue of outstanding peer connections. Read more

fn set_backlog(&self, value: i32) -> Result<(), Error>[src]

Set the maximum length of the queue of outstanding peer connections for the specified socket; this only applies to connection-oriented transports. Read more

fn heartbeat_interval(&self) -> Result<Duration, Error>[src]

The interval between sending ZMTP heartbeats.

fn set_heartbeat_interval(&self, duration: Duration) -> Result<(), Error>[src]

Sets the interval between sending ZMTP PINGs (aka. heartbeats). Read more

fn heartbeat_timeout(&self) -> Result<Duration, Error>[src]

How long to wait before timing-out a connection after sending a PING ZMTP command and not receiving any traffic. Read more

fn set_heartbeat_timeout(&self, duration: Duration) -> Result<(), Error>[src]

How long to wait before timing-out a connection after sending a PING ZMTP command and not receiving any traffic. Read more

fn heartbeat_ttl(&self) -> Result<Duration, Error>[src]

The timeout on the remote peer for ZMTP heartbeats. If this option and heartbeat_interval is not None the remote side shall time out the connection if it does not receive any more traffic within the TTL period. Read more

fn set_heartbeat_ttl(&self, duration: Duration) -> Result<(), Error>[src]

Set timeout on the remote peer for ZMTP heartbeats. If this option and heartbeat_interval is not None the remote side shall time out the connection if it does not receive any more traffic within the TTL period. Read more

fn linger(&self) -> Result<Option<Duration>, Error>[src]

Returns the linger period for the socket shutdown.

fn set_linger(&self, maybe: Option<Duration>) -> Result<(), Error>[src]

Sets the linger period for the socket shutdown. Read more

fn mechanism(&self) -> Mechanism[src]

Returns the socket's [Mechanism]. Read more

fn set_mechanism<M>(&self, mechanism: M) -> Result<(), Error> where
    M: Into<Mechanism>, 
[src]

Set the socket's [Mechanism]. # Example ``` # use failure::Error; # # fn main() -> Result<(), Error> { use libzmq::{prelude::*, Client, auth::{PlainClientCreds, Mechanism}}; Read more

impl Sync for Server[src]

impl Send for Server[src]

impl PartialEq<Server> for Server[src]

impl Clone for Server[src]

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl Eq for Server[src]

impl Debug for Server[src]

Blanket Implementations

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

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

type Owned = T

The resulting type after obtaining ownership.

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

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<T> Borrow<T> for T where
    T: ?Sized
[src]

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

impl<T> Any for T where
    T: 'static + ?Sized
[src]