use of io.vertx.core.datagram.DatagramSocketOptions in project vert.x by eclipse.
the class DatagramTest method testSendReceive.
@Test
public void testSendReceive() {
peer1 = vertx.createDatagramSocket(new DatagramSocketOptions());
peer2 = vertx.createDatagramSocket(new DatagramSocketOptions());
peer2.exceptionHandler(t -> fail(t.getMessage()));
peer2.listen(1234, "127.0.0.1", ar -> {
assertTrue(ar.succeeded());
Buffer buffer = TestUtils.randomBuffer(128);
peer2.handler(packet -> {
Buffer data = packet.data();
ByteBuf buff = data.getByteBuf();
while (buff != buff.unwrap() && buff.unwrap() != null) {
buff = buff.unwrap();
}
assertTrue("Was expecting an unpooled buffer instead of " + buff.getClass().getSimpleName(), buff.getClass().getSimpleName().contains("Unpooled"));
assertEquals(buffer, data);
testComplete();
});
peer1.send(buffer, 1234, "127.0.0.1", ar2 -> assertTrue(ar2.succeeded()));
});
await();
}
use of io.vertx.core.datagram.DatagramSocketOptions in project vert.x by eclipse.
the class DatagramExamples method example4.
public void example4(Vertx vertx) {
DatagramSocket socket = vertx.createDatagramSocket(new DatagramSocketOptions());
Buffer buffer = Buffer.buffer("content");
// Send a Buffer to a multicast address
socket.send(buffer, 1234, "230.0.0.1", asyncResult -> {
System.out.println("Send succeeded? " + asyncResult.succeeded());
});
}
use of io.vertx.core.datagram.DatagramSocketOptions in project vert.x by eclipse.
the class DatagramExamples method example2.
public void example2(Vertx vertx) {
DatagramSocket socket = vertx.createDatagramSocket(new DatagramSocketOptions());
Buffer buffer = Buffer.buffer("content");
// Send a Buffer
socket.send(buffer, 1234, "10.0.0.1", asyncResult -> {
System.out.println("Send succeeded? " + asyncResult.succeeded());
});
// Send a String
socket.send("A string used as content", 1234, "10.0.0.1", asyncResult -> {
System.out.println("Send succeeded? " + asyncResult.succeeded());
});
}
use of io.vertx.core.datagram.DatagramSocketOptions in project vert.x by eclipse.
the class DatagramExamples method example3.
public void example3(Vertx vertx) {
DatagramSocket socket = vertx.createDatagramSocket(new DatagramSocketOptions());
socket.listen(1234, "0.0.0.0", asyncResult -> {
if (asyncResult.succeeded()) {
socket.handler(packet -> {
});
} else {
System.out.println("Listen failed" + asyncResult.cause());
}
});
}
use of io.vertx.core.datagram.DatagramSocketOptions in project vert.x by eclipse.
the class DatagramExamples method example6.
public void example6(Vertx vertx) {
DatagramSocket socket = vertx.createDatagramSocket(new DatagramSocketOptions());
socket.listen(1234, "0.0.0.0", asyncResult -> {
if (asyncResult.succeeded()) {
socket.handler(packet -> {
});
socket.listenMulticastGroup("230.0.0.1", asyncResult2 -> {
if (asyncResult2.succeeded()) {
socket.unlistenMulticastGroup("230.0.0.1", asyncResult3 -> {
System.out.println("Unlisten succeeded? " + asyncResult3.succeeded());
});
} else {
System.out.println("Listen failed" + asyncResult2.cause());
}
});
} else {
System.out.println("Listen failed" + asyncResult.cause());
}
});
}
Aggregations