Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Sender.
- public class ZSender {
- public static void main(String[] args) throws InterruptedException {
- ZMQ.Context ctx = ZMQ.context(1);
- ZMQ.Socket client = ctx.socket(DEALER);
- client.connect("tcp://" + args[0] + ":222");
- long i = 0;
- while (true) {
- assert client.send("", SNDMORE);
- assert client.send(("hello" + i), 0);
- i++;
- TimeUnit.SECONDS.sleep(1);
- }
- }
- }
- // Receiver.
- public class ZReceiver {
- public static void main(String[] args) throws InterruptedException {
- ZMQ.Context ctx = ZMQ.context(1);
- ZMQ.Socket server = ctx.socket(ROUTER);
- server.bind("tcp://*:222");
- while (true) {
- byte[] identity = server.recv();
- assert identity != null;
- byte[] div = server.recv();
- assert div != null;
- byte[] hello = server.recv();
- assert hello != null;
- System.out.println("receiver got: " + new String(hello));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment