Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import org.zeromq.ZMQ;
- public class SubTest
- {
- public static void main(String[] args)
- {
- ZMQ.Context context = ZMQ.context(1);
- ZMQ.Socket subSocket = context.socket(ZMQ.SUB);
- subSocket.subscribe("".getBytes());
- subSocket.setHWM(10);
- subSocket.connect("tcp://127.0.0.1:5555");
- int expectedMsgId = 1;
- while (true)
- {
- String msg = new String(subSocket.recv(0));
- int rxMsgId = Integer.parseInt(msg);
- if (rxMsgId != expectedMsgId)
- {
- System.out.printf("Expected %d, but received %d\n", expectedMsgId, rxMsgId);
- }
- else
- {
- System.out.printf("Received expected message: %d\n", rxMsgId);
- }
- expectedMsgId = rxMsgId + 1;
- }
- }
- }
- import org.zeromq.ZMQ;
- public class PubTest
- {
- public static void main(String[] args)
- {
- ZMQ.Context context = ZMQ.context(1);
- ZMQ.Socket pubSocket = context.socket(ZMQ.PUB);
- pubSocket.setHWM(10);
- pubSocket.bind("tcp://*:5555");
- int msgId = 0;
- while (true)
- {
- String msg = (++msgId) + "";
- pubSocket.send(msg.getBytes(), 0);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement