Created
June 30, 2015 09:49
-
-
Save dnaeon/2b5da5358bdcdf115cef to your computer and use it in GitHub Desktop.
rust-libzmq-helloworld
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern crate libc; | |
extern crate libzmq; | |
use std::ffi; | |
use std::thread; | |
unsafe fn helloworld_client() { | |
let context = libzmq::zmq_ctx_new(); | |
let receiver = libzmq::zmq_socket(context, libzmq::ZMQ_REQ as libc::c_int); | |
let endpoint = ffi::CString::new("tcp://127.0.0.1:5555").unwrap(); | |
assert_eq!(libzmq::zmq_connect(receiver, endpoint.as_ptr()), 0); | |
let data = ffi::CString::new("Hello").unwrap(); | |
let buffer = ffi::CString::new("").unwrap(); | |
for request in 0..10 { | |
println!("Sending request #{}", request); | |
libzmq::zmq_send(receiver, data.as_ptr() as *const libc::c_void, 5, 0); | |
thread::sleep_ms(1000); | |
libzmq::zmq_recv(receiver, buffer.as_ptr() as *mut libc::c_void, 5, 0); | |
println!("Received reply!"); | |
} | |
} | |
fn main() { | |
unsafe { helloworld_client(); } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment