Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Client:
- import org.zeromq.ZMQ;
- import java.util.concurrent.TimeUnit;
- public class Client {
- public static void main(String[] args) throws InterruptedException {
- ZMQ.Context ctx = ZMQ.context(1);
- ZMQ.Socket client = ctx.socket(ZMQ.REQ);
- client.connect("tcp://localhost:222");
- long i = 0;
- while (true) {
- assert client.send(("hello" + i), 0);
- byte[] world = client.recv();
- assert world != null;
- System.out.println("hello/world complete.");
- i++;
- TimeUnit.SECONDS.sleep(1);
- }
- }
- }
- // Server:
- package org.zeromq;
- public class Server {
- public static void main(String[] args) throws InterruptedException {
- ZMQ.Context ctx = ZMQ.context(1);
- ZMQ.Socket server = ctx.socket(ZMQ.REP);
- server.bind("tcp://*:222");
- while (true) {
- byte[] hello = server.recv();
- assert hello != null;
- assert server.send("world", 0);
- System.out.println("hello/world complete.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment