Example usage for io.vertx.core.datagram DatagramSocket listen

List of usage examples for io.vertx.core.datagram DatagramSocket listen

Introduction

In this page you can find the example usage for io.vertx.core.datagram DatagramSocket listen.

Prototype

@Fluent
DatagramSocket listen(int port, String host, Handler<AsyncResult<DatagramSocket>> handler);

Source Link

Document

Start listening on the given port and host.

Usage

From source file:examples.DatagramExamples.java

License:Open Source License

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 -> {
                // Do something with the packet
            });//from   www.  ja  v a  2s  .co m
        } else {
            System.out.println("Listen failed" + asyncResult.cause());
        }
    });
}

From source file:examples.DatagramExamples.java

License:Open Source License

public void example5(Vertx vertx) {
    DatagramSocket socket = vertx.createDatagramSocket(new DatagramSocketOptions());
    socket.listen(1234, "0.0.0.0", asyncResult -> {
        if (asyncResult.succeeded()) {
            socket.handler(packet -> {
                // Do something with the packet
            });/*from   ww  w.  j ava  2s.  co m*/

            // join the multicast group
            socket.listenMulticastGroup("230.0.0.1", asyncResult2 -> {
                System.out.println("Listen succeeded? " + asyncResult2.succeeded());
            });
        } else {
            System.out.println("Listen failed" + asyncResult.cause());
        }
    });
}

From source file:examples.DatagramExamples.java

License:Open Source License

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 -> {
                // Do something with the packet
            });/*w  w  w .  j a v  a 2s.c om*/

            // join the multicast group
            socket.listenMulticastGroup("230.0.0.1", asyncResult2 -> {
                if (asyncResult2.succeeded()) {
                    // will now receive packets for group

                    // do some work

                    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());
        }
    });
}

From source file:org.hawkular.metrics.clients.ptrans.collectd.CollectdServer.java

License:Apache License

@Override
public void start(Future<Void> startFuture) throws Exception {
    DatagramSocket socket = vertx.createDatagramSocket();
    socket.handler(this::handlePacket);
    socket.listen(port, "0.0.0.0", result -> {
        if (result.succeeded()) {
            startFuture.complete();//from   w  ww.j av a2 s  .c om
        } else {
            startFuture.fail(result.cause());
        }
    });
}