We need to broadcast an Object(Pojo) over UDP channel using Netty 4.0.0 binary.
In Netty 4.0.0 it allows us to use only DatagramPacket class to send UDP packet.
This class only accepts ByteBuf as an argument.
Is there any other way,we can send a Pojo over UDP channel ?
To further clarify,we were doing as follows:
Initializing settings for UDP channel
ConnectionlessBootstrap udpBootstrap;
udpBootstrap.setPipelineFactory(new ChannelPipelineFactory() {
public ChannelPipeline getPipeline() throws Exception {
return Channels.pipeline(
new ObjectEncoder(),
new ObjectDecoder(new NettyElementInfo()),
new UDPBroadcastHandler());
}
});
udpBootstrap.setOption("broadcast", true);
//datagramChannel = (DatagramChannel) udpBootstrap.bind(new InetSocketAddress(udp_port));
datagramChannel = (DatagramChannel) udpBootstrap.bind(new InetSocketAddress(0));
Here,NettyElementInfo implements Serializable and ClassResolver interfaces.We were trying to broadcast this pojo as follows:
channel.write(new NettyElementInfo(),
new InetSocketAddress("255.255.255.255", 9555));
At the receiving end, we were doing same as above for the Initialization part.However,in the handler were getting the Pojo as follows:
NettyElementInfo elementInfo = (NettyElementInfo)e.getMessage();
This was successfully done using netty 3.5.x
How to replicate this scenario using Netty 4.0.0. Please provide us with the sample code.