1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
// Very basic example to listen tcp socket from zmq using STREAM sockets
// You can use telnet to send messages and they will be output to console
// ZMQ_STREAM socket will prepend socket identity on message, that's why we use recv_multipart here
use std::str;
fn main() {
println!("Hello, world!");
let ctx = zmq::Context::new();
let socket = ctx.socket(zmq::STREAM).unwrap();
socket.bind("tcp://*:8888").unwrap();
loop {
let data = socket.recv_multipart(0).unwrap();
println!(
"Identity: {:?} Message : {}",
data[0],
str::from_utf8(&data[1]).unwrap()
);
}
}
|