Guest User

Does ZMQ handle tcp-RST?

a guest
Dec 17th, 2013
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.96 KB | None | 0 0
  1. // Client with HWM=0.
  2.  
  3. import org.zeromq.ZMQ;
  4.  
  5. import java.util.concurrent.TimeUnit;
  6.  
  7. import static org.zeromq.ZMQ.DEALER;
  8. import static org.zeromq.ZMQ.SNDMORE;
  9.  
  10. public class Client {
  11.  
  12.   public static void main(String[] args) throws InterruptedException {
  13.     ZMQ.Context ctx = ZMQ.context(1);
  14.  
  15.     ZMQ.Socket client = ctx.socket(DEALER);
  16.     client.setSndHWM(0);  // HWM is setting to 0 in a hope .send() will return false at some point.
  17.     client.connect("tcp://localhost:222");
  18.  
  19.     long i = 0;
  20.     while (true) {
  21.       // send().
  22.       assert client.send("", SNDMORE); // this line always passes.
  23.       assert client.send(("hello" + i), 0); // this line always passes.
  24.  
  25.       // recv().
  26.       byte[] world = client.recv();
  27.       assert world != null;
  28.  
  29.       System.out.println("hello/world complete.");
  30.  
  31.       i++;
  32.       TimeUnit.SECONDS.sleep(1);
  33.     }
  34.   }
  35. }
  36.  
  37. // ROUTER-server which can be killed sporadically, thereby generating RST to client.
Advertisement
Add Comment
Please, Sign In to add comment