use of zmq.SocketBase in project jeromq by zeromq.
the class BindSrcAddressTest method test.
@Test
public void test() throws IOException {
Ctx ctx = ZMQ.createContext();
assert (ctx != null);
SocketBase socket = ZMQ.socket(ctx, ZMQ.ZMQ_PUB);
assert (socket != null);
int port1 = Utils.findOpenPort();
int port2 = Utils.findOpenPort();
int port3 = Utils.findOpenPort();
boolean rc = ZMQ.connect(socket, "tcp://127.0.0.1:0;localhost:" + port1);
assert (rc);
rc = ZMQ.connect(socket, "tcp://localhost:" + port3 + ";localhost:" + port2);
assert (rc);
// rc = ZMQ.connect(socket, "tcp://lo:" + port3 + ";localhost:" + port2);
// assert (rc);
ZMQ.close(socket);
ZMQ.term(ctx);
}
use of zmq.SocketBase in project jeromq by zeromq.
the class LocalLat method main.
public static void main(String[] args) {
String bindTo;
int roundtripCount;
int messageSize;
Ctx ctx;
SocketBase s;
boolean rc;
int n;
int i;
Msg msg;
if (args.length != 3) {
printf("usage: local_lat <bind-to> <message-size> " + "<roundtrip-count>\n");
return;
}
bindTo = args[0];
messageSize = atoi(args[1]);
roundtripCount = atoi(args[2]);
ctx = ZMQ.init(1);
if (ctx == null) {
printf("error in init: %s\n");
return;
}
s = ZMQ.socket(ctx, ZMQ.ZMQ_REP);
if (s == null) {
printf("error in socket: %s\n", ZMQ.strerror(ctx.errno().get()));
return;
}
rc = ZMQ.bind(s, bindTo);
if (!rc) {
printf("error in bind: %s\n", ZMQ.strerror(s.errno()));
return;
}
for (i = 0; i != roundtripCount; i++) {
msg = ZMQ.recvMsg(s, 0);
if (msg == null) {
printf("error in recvmsg: %s\n", ZMQ.strerror(s.errno()));
return;
}
if (ZMQ.msgSize(msg) != messageSize) {
printf("message of incorrect size received\n");
return;
}
n = ZMQ.sendMsg(s, msg, 0);
if (n < 0) {
printf("error in sendmsg: %s\n", ZMQ.strerror(s.errno()));
return;
}
}
ZMQ.sleep(1000);
ZMQ.close(s);
ZMQ.term(ctx);
}
use of zmq.SocketBase in project jeromq by zeromq.
the class StreamEngineTest method testEncoderFlipIssue520.
@Test
public void testEncoderFlipIssue520() throws IOException {
Ctx ctx = ZMQ.createContext();
assertThat(ctx, notNullValue());
SocketBase sender = ZMQ.socket(ctx, ZMQ.ZMQ_PUSH);
assertThat(sender, notNullValue());
boolean rc = ZMQ.setSocketOption(sender, ZMQ.ZMQ_IMMEDIATE, false);
assertThat(rc, is(true));
SocketBase receiver = ZMQ.socket(ctx, ZMQ.ZMQ_PULL);
assertThat(receiver, notNullValue());
String addr = "tcp://localhost:*";
rc = ZMQ.bind(receiver, addr);
assertThat(rc, is(true));
addr = (String) ZMQ.getSocketOptionExt(receiver, ZMQ.ZMQ_LAST_ENDPOINT);
assertThat(addr, notNullValue());
rc = ZMQ.connect(sender, addr);
assertThat(rc, is(true));
final int headerSize = 8 + 1;
// first message + second message header fill the buffer
byte[] msg1 = msg(Config.OUT_BATCH_SIZE.getValue() - 2 * headerSize);
// second message will go in zero-copy mode
byte[] msg2 = msg(Config.OUT_BATCH_SIZE.getValue());
exchange(sender, receiver, msg1, msg2, msg1, msg2);
ZMQ.close(receiver);
ZMQ.close(sender);
ZMQ.term(ctx);
}
use of zmq.SocketBase in project jeromq by zeromq.
the class CustomDecoderTest method testAssignCustomDecoder.
@SuppressWarnings("deprecation")
@Test
public void testAssignCustomDecoder() {
Ctx ctx = ZMQ.createContext();
SocketBase socket = ctx.createSocket(ZMQ.ZMQ_PAIR);
boolean rc = socket.setSocketOpt(ZMQ.ZMQ_DECODER, CustomDecoder.class);
assertThat(rc, is(true));
ZMQ.close(socket);
ZMQ.term(ctx);
}
use of zmq.SocketBase in project jeromq by zeromq.
the class CustomDecoderTest method testAssignWrongCustomDecoder.
@SuppressWarnings("deprecation")
@Test(expected = ZError.InstantiationException.class)
public void testAssignWrongCustomDecoder() {
Ctx ctx = ZMQ.createContext();
SocketBase socket = ctx.createSocket(ZMQ.ZMQ_PAIR);
try {
socket.setSocketOpt(ZMQ.ZMQ_DECODER, WrongDecoder.class);
} finally {
ZMQ.close(socket);
ZMQ.term(ctx);
}
}
Aggregations