Example usage for io.netty.channel.socket DatagramPacket content

List of usage examples for io.netty.channel.socket DatagramPacket content

Introduction

In this page you can find the example usage for io.netty.channel.socket DatagramPacket content.

Prototype

ByteBuf content();

Source Link

Document

Return the data which is held by this ByteBufHolder .

Usage

From source file:se.sics.kompics.network.netty.DatagramHandler.java

License:Open Source License

@Override
protected void messageReceived(ChannelHandlerContext ctx, DatagramPacket msg) throws Exception {
    try {/*from   w  w w . j  av a2 s  .c o  m*/
        Object m = Serializers.fromBinary(msg.content(), Optional.absent());
        if (m instanceof Msg) {
            component.deliverMessage((Msg) m);
        } else {
            NettyNetwork.LOG.warn("Got unexpected Datagram message type: {} -> {}",
                    m.getClass().getCanonicalName(), m);
        }
    } catch (Exception e) { // Catch anything...the Serializer could through any kind of weird exception if you get message that were send by someone else
        NettyNetwork.LOG.warn("Got weird Datagram message, ignoring it: {}",
                ByteBufUtil.hexDump(msg.content()));
    }
}