ZMQ_Receive.java
Go to the documentation of this file.
1 package grl.flatBufferTesting;
2 
3 import java.util.concurrent.TimeUnit;
4 
5 import org.zeromq.ZMQ;
6 
7 //https://github.com/miniway/jeromq/tree/master/src/test/java/guide
8 public class ZMQ_Receive {
9  static final int NUM_MSG = 10;
10  static final String ADDRESS = "tcp://127.0.0.1:5563";
11  public static void main(String[] args) throws Exception {
12  long bTime = System.currentTimeMillis();
13 
14  // Prepare our context and dealer
15  ZMQ.Context context = ZMQ.context(1);
16  ZMQ.Socket subscriber = context.socket(ZMQ.DEALER);
17 
18  subscriber.connect(ADDRESS);
19  subscriber.setRcvHWM(1000000);
20  System.out.println("Connected to: "+ADDRESS);
21 
22  int c = 0;
23  while (true) {
24  byte [] msg = subscriber.recv();
25  c++;
26  System.out.println(msg);
27  if (c >= NUM_MSG) {
28  break;
29  }
30  }
31 
32  long secs = TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis()- bTime);
33  System.out.println("Wuserver done at " + c + " in " + secs + " seconds");
34  subscriber.close();
35  //Thread.sleep(1000);
36  context.term();
37  System.exit(1);
38  }
39 }
static void main(String[] args)