File: logserver.rs

package info (click to toggle)
rust-zmq 0.9.2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 540 kB
  • sloc: makefile: 2
file content (22 lines) | stat: -rw-r--r-- 648 bytes parent folder | download | duplicates (2)
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()
        );
    }
}