Created
November 30, 2013 13:02
-
-
Save cmouse/7718824 to your computer and use it in GitHub Desktop.
Request script
This file contains 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
#include <iostream> | |
#include <zmq.hpp> | |
using namespace std; | |
class TestClass { | |
public: | |
TestClass(): d_ctx(1), d_sock(d_ctx, ZMQ_REQ) { | |
d_sock.connect("ipc:///tmp/pdns.0"); | |
}; | |
zmq::context_t d_ctx; | |
zmq::socket_t d_sock; | |
void send() { | |
zmq::message_t message(100); | |
strcpy(reinterpret_cast<char*>(message.data()), "hello, world"); | |
d_sock.send(message, 0); | |
}; | |
void recv() { | |
zmq_pollitem_t item; | |
item.socket = d_sock; | |
item.events = ZMQ_POLLIN; | |
if (zmq::poll(&item, 1, 100000)>0) { | |
zmq::message_t message; | |
d_sock.recv(&message, 0); | |
cout << reinterpret_cast<char*>(message.data()) << endl; | |
} else { | |
cout << "Timeout waiting for data" << endl; | |
} | |
}; | |
}; | |
int main(int argc, const char *argv[]) { | |
TestClass t; | |
t.send(); | |
t.recv(); | |
t.send(); | |
t.recv(); | |
t.send(); | |
t.recv(); | |
t.send(); | |
t.recv(); | |
return 0; | |
} |
This file contains 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
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'zero_mq' | |
begin | |
line = "" | |
context = ZeroMQ::Context.new | |
socket = context.socket ZMQ::REP | |
socket.setsockopt(ZMQ::HWM, 1000) | |
socket.bind("ipc:///tmp/pdns.0") | |
while true do | |
rc = socket.recv_string line | |
p line | |
socket.send_string "why, hello" | |
end | |
rescue SystemExit, Interrupt | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment