Guest User

Updated Client with reconnect.

a guest
Dec 17th, 2013
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.81 KB | None | 0 0
  1. public class ZClient {
  2.  
  3.     public static void main(String[] args) throws InterruptedException {
  4.         ZMQ.Context ctx = ZMQ.context(1);
  5.  
  6.         ZMQ.Socket client = ctx.socket(DEALER);
  7.         client.setReceiveTimeOut(1000);  //  specify 1 sec  timeout for .recv().
  8.         client.connect("tcp://" + args[0] + ":222");
  9.  
  10.         long i = 0;
  11.         while (true) {
  12.             // send().
  13.             assert client.send("", SNDMORE);
  14.             assert client.send(("hello" + i), 0);
  15.  
  16.             // recv().
  17.             byte[] world = client.recv();
  18.             if (world != null) { // if got null -- no worry, just send again one more time.
  19.                 i++;
  20.                 System.out.println("hello/world complete.");
  21.                 TimeUnit.SECONDS.sleep(1);
  22.             }
  23.         }
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment