Guest User

reconnect failed after iptables tricks

a guest
Dec 17th, 2013
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.00 KB | None | 0 0
  1. // Client:
  2.  
  3. import org.zeromq.ZMQ;
  4. import java.util.concurrent.TimeUnit;
  5.  
  6. public class Client {
  7.  
  8.   public static void main(String[] args) throws InterruptedException {
  9.     ZMQ.Context ctx = ZMQ.context(1);
  10.  
  11.     ZMQ.Socket client = ctx.socket(ZMQ.REQ);
  12.     client.connect("tcp://localhost:222");
  13.  
  14.     long i = 0;
  15.     while (true) {
  16.       assert client.send(("hello" + i), 0);
  17.       byte[] world = client.recv();
  18.       assert world != null;
  19.       System.out.println("hello/world complete.");
  20.       i++;
  21.       TimeUnit.SECONDS.sleep(1);
  22.     }
  23.   }
  24. }
  25.  
  26. // Server:
  27.  
  28. package org.zeromq;
  29.  
  30. public class Server {
  31.  
  32.   public static void main(String[] args) throws InterruptedException {
  33.     ZMQ.Context ctx = ZMQ.context(1);
  34.  
  35.     ZMQ.Socket server = ctx.socket(ZMQ.REP);
  36.     server.bind("tcp://*:222");
  37.  
  38.     while (true) {
  39.       byte[] hello = server.recv();
  40.       assert hello != null;
  41.       assert server.send("world", 0);
  42.       System.out.println("hello/world complete.");
  43.     }
  44.   }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment