import org.zeromq.ZContext;
import org.zeromq.ZMQ;
public class Server {
public static void main(String[] args) {
try (ZContext context = new ZContext()) {
ZMQ.Socket socket = context.createSocket(ZMQ.REP);
socket.bind("tcp://localhost:5555");
while (!Thread.currentThread().isInterrupted()) {
byte[] request = socket.recv(0);
String message = new String(request, ZMQ.CHARSET);
String response = "Hello, " + message;
socket.send(response.getBytes(ZMQ.CHARSET), 0);
}
}
}
}
import org.zeromq.ZContext;
import org.zeromq.ZMQ;
public class Client {
public static void main(String[] args) {
try (ZContext context = new ZContext()) {
ZMQ.Socket socket = context.createSocket(ZMQ.REQ);
socket.connect("tcp://localhost:5555");
for (int i = 0; i < 5; i++) {
String request = "World " + i;
socket.send(request.getBytes(ZMQ.CHARSET), 0);
byte[] response = socket.recv(0);
}
}
}
}