Пример #1
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);
  }