Esempio n. 1
0
  @Test
  public void testPairInproc() {

    Ctx ctx = ZMQ.zmq_init(1);
    assertThat(ctx, notNullValue());
    SocketBase sb = ZMQ.zmq_socket(ctx, ZMQ.ZMQ_PAIR);
    assertThat(sb, notNullValue());
    boolean brc = ZMQ.zmq_bind(sb, "inproc://a");
    assertThat(brc, is(true));

    SocketBase sc = ZMQ.zmq_socket(ctx, ZMQ.ZMQ_PAIR);
    assertThat(sc, notNullValue());
    brc = ZMQ.zmq_connect(sc, "inproc://a");
    assertThat(brc, is(true));

    TestHelper.bounce(sb, sc);

    //  Tear down the wiring.
    ZMQ.zmq_close(sb);
    ZMQ.zmq_close(sc);
    ZMQ.zmq_term(ctx);
  }
Esempio n. 2
0
  public static void bounce(SocketBase sb, SocketBase sc) {
    byte[] content = "12345678ABCDEFGH12345678abcdefgh".getBytes();

    //  Send the message.
    int rc = ZMQ.zmq_send(sc, content, 32, ZMQ.ZMQ_SNDMORE);
    assert (rc == 32);
    rc = ZMQ.zmq_send(sc, content, 32, 0);
    assertThat(rc, is(32));

    //  Bounce the message back.
    Msg msg;
    msg = ZMQ.zmq_recv(sb, 0);
    assert (msg.size() == 32);
    long rcvmore = ZMQ.zmq_getsockopt(sb, ZMQ.ZMQ_RCVMORE);
    assert (rcvmore == 1);
    msg = ZMQ.zmq_recv(sb, 0);
    assert (rc == 32);
    rcvmore = ZMQ.zmq_getsockopt(sb, ZMQ.ZMQ_RCVMORE);
    assert (rcvmore == 0);
    rc = ZMQ.zmq_send(sb, new Msg(msg), ZMQ.ZMQ_SNDMORE);
    assert (rc == 32);
    rc = ZMQ.zmq_send(sb, new Msg(msg), 0);
    assert (rc == 32);

    //  Receive the bounced message.
    msg = ZMQ.zmq_recv(sc, 0);
    assert (rc == 32);
    rcvmore = ZMQ.zmq_getsockopt(sc, ZMQ.ZMQ_RCVMORE);
    assertThat(rcvmore, is(1L));
    msg = ZMQ.zmq_recv(sc, 0);
    assert (rc == 32);
    rcvmore = ZMQ.zmq_getsockopt(sc, ZMQ.ZMQ_RCVMORE);
    assertThat(rcvmore, is(0L));
    //  Check whether the message is still the same.
    // assert (memcmp (buf2, content, 32) == 0);
  }