pub struct Context { /* private fields */ }
Implementations§
Source§impl Context
impl Context
Sourcepub fn new() -> Result<Context, Error>
pub fn new() -> Result<Context, Error>
Create new 0MQ context
Binding of void *zmq_ctx_new ();
The function creates a new ØMQ context.
§Thread safety
A ØMQ context is thread safe and may be shared among as many application threads as necessary, without any additional locking required on the part of the caller.
Examples found in repository?
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
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}
Sourcepub fn shutdown(&mut self) -> Result<(), Error>
pub fn shutdown(&mut self) -> Result<(), Error>
Shutdown a 0MQ context
Binding of int zmq_ctx_shutdown (void *context);
The function will shutdown the ØMQ context context. Context shutdown will cause any blocking operations currently in progress on sockets open within context to return immediately with an error code of ETERM. With the exception of Socket::Close(), any further operations on sockets open within context will fail with an error code of ETERM.
Examples found in repository?
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}
pub fn get_io_threads(&self) -> Result<i32, Error>
pub fn get_max_sockets(&self) -> Result<i32, Error>
pub fn get_socket_limit(&self) -> Result<i32, Error>
pub fn is_ipv6_enabled(&self) -> Result<bool, Error>
pub fn set_io_threads(&mut self, optval: i32) -> Result<(), Error>
pub fn set_max_sockets(&mut self, optval: i32) -> Result<(), Error>
pub fn set_thread_priority(&mut self, optval: i32) -> Result<(), Error>
pub fn set_thread_sched_policy(&mut self, optval: i32) -> Result<(), Error>
pub fn set_ipv6(&mut self, optval: i32) -> Result<(), Error>
Sourcepub fn socket(&self, t: SocketType) -> Result<Socket, Error>
pub fn socket(&self, t: SocketType) -> Result<Socket, Error>
Create 0MQ socket
Binding of void *zmq_socket (void *context, int type);
The type argument specifies the socket type, which determines the semantics of communication over the socket. The newly created socket is initially unbound, and not associated with any endpoints. In order to establish a message flow a socket must first be connected to at least one endpoint with Scoket::Connect, or at least one endpoint must be created for accepting incoming connections with Socket::Bind().
Examples found in repository?
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
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}