forked from rotty/zmq-tokio
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathresponder.rs
40 lines (32 loc) · 870 Bytes
/
responder.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
extern crate futures;
extern crate tokio_core;
extern crate zmq_tokio;
use futures::Stream;
use tokio_core::reactor::Core;
use zmq_tokio::zmq;
use zmq_tokio::{Context};
fn main() {
let ctx = Context::new();
let mut core = Core::new().unwrap();
let handle = core.handle();
let server = ctx.socket(zmq::REP, &handle).unwrap();
let _ = server.bind("tcp://127.0.0.1:78999").unwrap();
let server_stream = (&server)
.incoming()
.and_then(|msg| {
println!("server got: {:?}", msg.as_str());
Ok(msg)
})
.and_then(|msg| {
(&server).send(msg)
})
.and_then(|_| {
println!("server replied");
Ok(())
})
.for_each(|_| {
Ok(())
});
let _ = core.run(server_stream).unwrap();
::std::process::exit(0);
}