Struct Socket

Source
pub struct Socket { /* private fields */ }

Implementations§

Source§

impl Socket

Source

pub fn from_raw(socket: *mut c_void) -> Socket

Source

pub fn close(&mut self) -> Result<(), Error>

Close 0MQ socket

Binding of int zmq_close (void *s);

It’s not mandatory to call this function since socket can be closed automatically on dropping The function will destroy this socket. Any outstanding messages physically received from the network but not yet received by the application with recv() shall be discarded. The behaviour for discarding messages sent by the application with send() but not yet physically transferred to the network depends on the value of the ZMQ_LINGER socket option for the specified socket.

Examples found in repository?
examples/zguide/hwclient.rs (line 17)
4fn main() {
5    println!("Connecting to hello world server...");
6    let mut context = zmq::Context::new().unwrap();
7    let mut requester = context.socket(zmq::REQ).unwrap();
8    requester.connect("tcp://localhost:5555").unwrap();
9
10    for request_nbr in 0..10 {
11        let mut buffer: Vec<u8> = Vec::with_capacity(10);
12        println!("Sending Hello {}...", request_nbr);
13        requester.send_bytes("Hello".as_bytes(), 0).unwrap();
14        requester.recv_bytes_into_slice(&mut buffer, 0).unwrap();
15        println!("Received World {}", request_nbr);
16    }
17    requester.close().unwrap();
18    context.shutdown().unwrap();
19}
Source

pub fn bind(&mut self, endpoint: &str) -> Result<(), Error>

Accept incoming connections on a socket

Binding of int zmq_bind (void *socket, const char *endpoint);

The function binds the socket to a local endpoint and then accepts incoming connections on that endpoint.

Examples found in repository?
examples/zguide/hwserver.rs (line 10)
7fn main() {
8    let mut context = zmq::Context::new().unwrap();
9    let mut responder = context.socket(zmq::REP).unwrap();
10    responder.bind("tcp://*:5555").unwrap();
11
12    loop {
13        let mut buffer: Vec<u8> = Vec::with_capacity(10);
14        responder.recv_bytes_into_slice(&mut buffer, 0).unwrap();
15        println!("Received Hello");
16        sleep(Duration::from_secs(1));
17        responder.send_bytes("World".as_bytes(), 0).unwrap();
18    }
19}
Source

pub fn connect(&mut self, endpoint: &str) -> Result<(), Error>

Create outgoing connection from socket

Binding of int zmq_connect (void *socket, const char *endpoint);

The function connects the socket to an endpoint and then accepts incoming connections on that endpoint.

Examples found in repository?
examples/zguide/hwclient.rs (line 8)
4fn main() {
5    println!("Connecting to hello world server...");
6    let mut context = zmq::Context::new().unwrap();
7    let mut requester = context.socket(zmq::REQ).unwrap();
8    requester.connect("tcp://localhost:5555").unwrap();
9
10    for request_nbr in 0..10 {
11        let mut buffer: Vec<u8> = Vec::with_capacity(10);
12        println!("Sending Hello {}...", request_nbr);
13        requester.send_bytes("Hello".as_bytes(), 0).unwrap();
14        requester.recv_bytes_into_slice(&mut buffer, 0).unwrap();
15        println!("Received World {}", request_nbr);
16    }
17    requester.close().unwrap();
18    context.shutdown().unwrap();
19}
Source

pub fn unbind(&mut self, endpoint: &str) -> Result<(), Error>

Stop accepting connections on a socket

Binding of int zmq_unbind (void *socket, const char *endpoint);

The function will unbind a socket specified by the socket argument from the endpoint specified by the endpoint argument.

Source

pub fn disconnect(&mut self, endpoint: &str) -> Result<(), Error>

Disconnect a socket

Binding of int zmq_disconnect (void *socket, const char *endpoint);

The function will disconnect socket from the endpoint specified by the endpoint argument. Any outstanding messages physically received from the network but not yet received by the application with recv() will be discarded. The behaviour for discarding messages sent by the application with send() but not yet physically transferred to the network depends on the value of the ZMQ_LINGER socket option for the socket.

Source

pub fn send_msg( &mut self, msg: Message, flags: SocketFlag, ) -> Result<i32, Error>

Send a message part on a socket

Binding of int zmq_msg_send (zmq_msg_t *msg, void *socket, int flags);

Source

pub fn recv_into_msg( &mut self, msg: &mut Message, flags: SocketFlag, ) -> Result<i32, Error>

Receive a message part from a socket

Binding of int zmq_msg_recv (zmq_msg_t *msg, void *socket, int flags);

Source

pub fn recv_msg(&mut self, flags: SocketFlag) -> Result<Message, Error>

Receive a message part from a socket

Binding of int zmq_msg_recv (zmq_msg_t *msg, void *socket, int flags);

Source

pub fn send_bytes( &mut self, data: &[u8], flags: SocketFlag, ) -> Result<i32, Error>

Send bytes on a socket

Data will be copied into a Message object in order to be sent.

Examples found in repository?
examples/zguide/hwserver.rs (line 17)
7fn main() {
8    let mut context = zmq::Context::new().unwrap();
9    let mut responder = context.socket(zmq::REP).unwrap();
10    responder.bind("tcp://*:5555").unwrap();
11
12    loop {
13        let mut buffer: Vec<u8> = Vec::with_capacity(10);
14        responder.recv_bytes_into_slice(&mut buffer, 0).unwrap();
15        println!("Received Hello");
16        sleep(Duration::from_secs(1));
17        responder.send_bytes("World".as_bytes(), 0).unwrap();
18    }
19}
More examples
Hide additional examples
examples/zguide/hwclient.rs (line 13)
4fn main() {
5    println!("Connecting to hello world server...");
6    let mut context = zmq::Context::new().unwrap();
7    let mut requester = context.socket(zmq::REQ).unwrap();
8    requester.connect("tcp://localhost:5555").unwrap();
9
10    for request_nbr in 0..10 {
11        let mut buffer: Vec<u8> = Vec::with_capacity(10);
12        println!("Sending Hello {}...", request_nbr);
13        requester.send_bytes("Hello".as_bytes(), 0).unwrap();
14        requester.recv_bytes_into_slice(&mut buffer, 0).unwrap();
15        println!("Received World {}", request_nbr);
16    }
17    requester.close().unwrap();
18    context.shutdown().unwrap();
19}
Source

pub fn send_const_bytes( &mut self, data: &'static [u8], flags: SocketFlag, ) -> Result<i32, Error>

Send a constant-memory message part on a socket

Binding of ZMQ_EXPORT int zmq_send_const (void *s, const void *buf, size_t len, int flags);

The message buffer is assumed to be constant-memory(static) and will therefore not be copied or deallocated in any way

Source

pub fn send_str(&mut self, data: &str, flags: SocketFlag) -> Result<i32, Error>

Send a UTF-8 string on socket

Source

pub fn recv_bytes(&mut self, flags: SocketFlag) -> Result<Vec<u8>, Error>

Receive bytes from a socket

Source

pub fn recv_bytes_into_slice( &mut self, buffer: &mut [u8], flags: SocketFlag, ) -> Result<i32, Error>

Receive bytes into a mutable slice

§Caution

Any bytes exceeding the length of buffer will be truncated.

Examples found in repository?
examples/zguide/hwserver.rs (line 14)
7fn main() {
8    let mut context = zmq::Context::new().unwrap();
9    let mut responder = context.socket(zmq::REP).unwrap();
10    responder.bind("tcp://*:5555").unwrap();
11
12    loop {
13        let mut buffer: Vec<u8> = Vec::with_capacity(10);
14        responder.recv_bytes_into_slice(&mut buffer, 0).unwrap();
15        println!("Received Hello");
16        sleep(Duration::from_secs(1));
17        responder.send_bytes("World".as_bytes(), 0).unwrap();
18    }
19}
More examples
Hide additional examples
examples/zguide/hwclient.rs (line 14)
4fn main() {
5    println!("Connecting to hello world server...");
6    let mut context = zmq::Context::new().unwrap();
7    let mut requester = context.socket(zmq::REQ).unwrap();
8    requester.connect("tcp://localhost:5555").unwrap();
9
10    for request_nbr in 0..10 {
11        let mut buffer: Vec<u8> = Vec::with_capacity(10);
12        println!("Sending Hello {}...", request_nbr);
13        requester.send_bytes("Hello".as_bytes(), 0).unwrap();
14        requester.recv_bytes_into_slice(&mut buffer, 0).unwrap();
15        println!("Received World {}", request_nbr);
16    }
17    requester.close().unwrap();
18    context.shutdown().unwrap();
19}
Source

pub fn recv_string( &mut self, flags: SocketFlag, ) -> Result<Result<String, Vec<u8>>, Error>

Receive a UTF-8 string from socket

Source

pub fn socket_monitor( &mut self, endpoint: &str, events: &Vec<SocketEvent>, ) -> Result<(), Error>

Monitor socket events

Binding of int zmq_socket_monitor (void *socket, char *endpoint, int events);

The method lets an application thread track socket events (like connects) on a ZeroMQ socket

Source

pub fn run_proxy( frontend: &mut Socket, backend: &mut Socket, ) -> Result<(), Error>

Start built-in 0MQ proxy

Binding of int zmq_proxy (const void *frontend, const void *backend, const void *capture);

The function starts the built-in ØMQ proxy in the current application thread.

Source

pub fn run_proxy_ex( frontend: &mut Socket, backend: &mut Socket, capture: Option<&mut Socket>, control: Option<&mut Socket>, ) -> Result<(), Error>

Start built-in 0MQ proxy

Binding of int zmq_proxy (const void *frontend, const void *backend, const void *capture); or int zmq_proxy_steerable (const void *frontend, const void *backend, const void *capture, const void *control);

The function starts the built-in ØMQ proxy in the current application thread. The proxy will send all messages, received on both frontend and backend, to the capture socket. The capture socket should be a ZMQ_PUB, ZMQ_DEALER, ZMQ_PUSH, or ZMQ_PAIR socket. If the control socket is not None, the proxy supports control flow. If PAUSE is received on this socket, the proxy suspends its activities. If RESUME is received, it goes on. If TERMINATE is received, it terminates smoothly. At start, the proxy runs normally as if run_proxy was used.

Source

pub fn as_poll_item(&self) -> PollItem

Create a poll item from current socket

§Safty

There is no lifetime guarantee that poll item does not live out socket

Source

pub fn poll( items: &mut [PollItem], nitems: i32, timeout: i32, ) -> Result<i32, Error>

input/output multiplexing

Binding of int zmq_poll (zmq_pollitem_t *items, int nitems, long timeout);

Source

pub fn get_affinity(&self) -> Result<u64, Error>

Source

pub fn get_backlog(&self) -> Result<i32, Error>

Source

pub fn get_curve_publickey(&self) -> Result<Vec<u8>, Error>

Source

pub fn get_curve_printable_publickey(&self) -> Result<String, Error>

Source

pub fn get_curve_secretkey(&self) -> Result<Vec<u8>, Error>

Source

pub fn get_curve_printable_secretkey(&self) -> Result<String, Error>

Source

pub fn get_curve_serverkey(&self) -> Result<Vec<u8>, Error>

Source

pub fn get_curve_printable_serverkey(&self) -> Result<String, Error>

Source

pub fn get_events(&self) -> Result<PollEvent, Error>

Source

pub fn get_fd(&self) -> Result<SocketFd, Error>

Source

pub fn is_gssapi_plaintext(&self) -> Result<bool, Error>

Source

pub fn get_gssapi_principal(&self) -> Result<String, Error>

Source

pub fn is_gssapi_server(&self) -> Result<bool, Error>

Source

pub fn get_gssapi_service_principal(&self) -> Result<String, Error>

Source

pub fn get_handshake_ivl(&self) -> Result<i32, Error>

Source

pub fn get_identity(&self) -> Result<Vec<u8>, Error>

Source

pub fn is_immediate(&self) -> Result<bool, Error>

Source

pub fn is_ipv6_enabled(&self) -> Result<bool, Error>

Source

pub fn get_last_endpoint(&self) -> Result<String, Error>

Source

pub fn get_linger(&self) -> Result<i32, Error>

Source

pub fn get_max_msg_size(&self) -> Result<i64, Error>

Source

pub fn get_mechanism(&self) -> Result<i32, Error>

Source

pub fn get_multicast_hops(&self) -> Result<i32, Error>

Source

pub fn get_plain_password(&self) -> Result<String, Error>

Source

pub fn is_plain_server(&self) -> Result<bool, Error>

Source

pub fn get_plain_username(&self) -> Result<String, Error>

Source

pub fn get_rate(&self) -> Result<i32, Error>

Source

pub fn get_rcvbuf(&self) -> Result<i32, Error>

Source

pub fn get_rcvhwm(&self) -> Result<i32, Error>

Source

pub fn can_rcvmore(&self) -> Result<bool, Error>

Source

pub fn get_rcvtimeo(&self) -> Result<i32, Error>

Source

pub fn get_reconnect_ivl(&self) -> Result<i32, Error>

Source

pub fn get_reconnect_ivl_max(&self) -> Result<i32, Error>

Source

pub fn get_recovery_ivl(&self) -> Result<i32, Error>

Source

pub fn get_sndbuf(&self) -> Result<i32, Error>

Source

pub fn get_sndhwm(&self) -> Result<i32, Error>

Source

pub fn get_sndtimeo(&self) -> Result<i32, Error>

Source

pub fn get_tcp_keepalive(&self) -> Result<i32, Error>

Source

pub fn get_tcp_keepalive_cnt(&self) -> Result<i32, Error>

Source

pub fn get_tcp_keepalive_idle(&self) -> Result<i32, Error>

Source

pub fn get_tcp_keepalive_intvl(&self) -> Result<i32, Error>

Source

pub fn get_tos(&self) -> Result<i32, Error>

Source

pub fn get_type(&self) -> Result<SocketType, Error>

Source

pub fn get_zap_domain(&self) -> Result<String, Error>

Source

pub fn set_affinity(&self, optval: &u64) -> Result<(), Error>

Source

pub fn set_backlog(&self, optval: &i32) -> Result<(), Error>

Source

pub fn set_connect_rid(&self, optval: &[u8]) -> Result<(), Error>

Source

pub fn set_conflate(&self, optval: &i32) -> Result<(), Error>

Source

pub fn set_curve_publickey(&self, optval: &[u8]) -> Result<(), Error>

Source

pub fn set_curve_plaintext_publickey(&self, optval: &str) -> Result<(), Error>

Source

pub fn set_curve_secretkey(&self, optval: &[u8]) -> Result<(), Error>

Source

pub fn set_curve_plaintext_secretkey(&self, optval: &str) -> Result<(), Error>

Source

pub fn set_curve_server(&self, optval: &i32) -> Result<(), Error>

Source

pub fn set_curve_serverkey(&self, optval: &[u8]) -> Result<(), Error>

Source

pub fn set_curve_plaintext_serverkey(&self, optval: &str) -> Result<(), Error>

Source

pub fn set_gssapi_plaintext(&self, optval: &i32) -> Result<(), Error>

Source

pub fn set_gssapi_principal(&self, optval: &str) -> Result<(), Error>

Source

pub fn set_gssapi_server(&self, optval: &i32) -> Result<(), Error>

Source

pub fn set_gssapi_service_principal(&self, optval: &str) -> Result<(), Error>

Source

pub fn set_handshake_ivl(&self, optval: &i32) -> Result<(), Error>

Source

pub fn set_identity(&self, optval: &[u8]) -> Result<(), Error>

Source

pub fn set_immediate(&self, optval: &i32) -> Result<(), Error>

Source

pub fn set_ipv6(&self, optval: &i32) -> Result<(), Error>

Source

pub fn set_linger(&self, optval: &i32) -> Result<(), Error>

Source

pub fn set_max_msg_size(&self, optval: &i64) -> Result<(), Error>

Source

pub fn set_multicast_hops(&self, optval: &i32) -> Result<(), Error>

Source

pub fn set_plain_password(&self, optval: &str) -> Result<(), Error>

Source

pub fn set_plain_password_empty(&self) -> Result<(), Error>

Source

pub fn set_plain_server(&self, optval: &i32) -> Result<(), Error>

Source

pub fn set_plain_username(&self, optval: &str) -> Result<(), Error>

Source

pub fn set_plain_username_empty(&self) -> Result<(), Error>

Source

pub fn set_probe_router(&self, optval: &i32) -> Result<(), Error>

Source

pub fn set_rate(&self, optval: &i32) -> Result<(), Error>

Source

pub fn set_rcvbuf(&self, optval: &i32) -> Result<(), Error>

Source

pub fn set_rcvhwm(&self, optval: &i32) -> Result<(), Error>

Source

pub fn set_rcvtimeo(&self, optval: &i32) -> Result<(), Error>

Source

pub fn set_reconnect_ivl(&self, optval: &i32) -> Result<(), Error>

Source

pub fn set_reconnect_ivl_max(&self, optval: &i32) -> Result<(), Error>

Source

pub fn set_recovery_ivl(&self, optval: &i32) -> Result<(), Error>

Source

pub fn set_req_correlate(&self, optval: &i32) -> Result<(), Error>

Source

pub fn set_req_relaxed(&self, optval: &i32) -> Result<(), Error>

Source

pub fn set_router_handover(&self, optval: &i32) -> Result<(), Error>

Source

pub fn set_router_mandatory(&self, optval: &i32) -> Result<(), Error>

Source

pub fn set_router_raw(&self, optval: &i32) -> Result<(), Error>

Source

pub fn set_sndbuf(&self, optval: &i32) -> Result<(), Error>

Source

pub fn set_sndhwm(&self, optval: &i32) -> Result<(), Error>

Source

pub fn set_sndtimeo(&self, optval: &i32) -> Result<(), Error>

Source

pub fn set_subscribe(&self, optval: &[u8]) -> Result<(), Error>

Source

pub fn set_tcp_keepalive(&self, optval: &i32) -> Result<(), Error>

Source

pub fn set_tcp_keepalive_cnt(&self, optval: &i32) -> Result<(), Error>

Source

pub fn set_tcp_keepalive_idle(&self, optval: &i32) -> Result<(), Error>

Source

pub fn set_tcp_keepalive_intvl(&self, optval: &i32) -> Result<(), Error>

Source

pub fn set_tos(&self, optval: &i32) -> Result<(), Error>

Source

pub fn set_unsubscribe(&self, optval: &[u8]) -> Result<(), Error>

Source

pub fn set_xpub_verbose(&self, optval: &i32) -> Result<(), Error>

Source

pub fn set_zqp_domain(&self, optval: &str) -> Result<(), Error>

Trait Implementations§

Source§

impl Drop for Socket

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Send for Socket

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.