M - the type of message to be encodedpublic class DatagramPacketEncoder<M> extends MessageToMessageEncoder<AddressedEnvelope<M,InetSocketAddress>>
AddressedEnvelope to DatagramPacket using
the specified message encoder. E.g.,
ChannelPipeline pipeline = ...;
pipeline.addLast("udpEncoder", new DatagramPacketEncoder(new ProtobufEncoder(...));
Note: As UDP packets are out-of-order, you should make sure the encoded message size are not greater than
the max safe packet size in your particular network path which guarantees no packet fragmentation.ChannelHandler.Sharable| Constructor and Description |
|---|
DatagramPacketEncoder(MessageToMessageEncoder<? super M> encoder)
Create an encoder that encodes the content in
AddressedEnvelope to DatagramPacket using
the specified message encoder. |
writeensureNotSharablepublic DatagramPacketEncoder(MessageToMessageEncoder<? super M> encoder)
AddressedEnvelope to DatagramPacket using
the specified message encoder.encoder - the specified message encoderpublic boolean acceptOutboundMessage(Object msg) throws Exception
MessageToMessageEncodertrue if the given message should be handled. If false it will be passed to the next
ChannelOutboundHandler in the ChannelPipeline.acceptOutboundMessage in class MessageToMessageEncoder<AddressedEnvelope<M,InetSocketAddress>>Exceptionprotected void encode(ChannelHandlerContext ctx, AddressedEnvelope<M,InetSocketAddress> msg, List<Object> out) throws Exception
MessageToMessageEncoderencode in class MessageToMessageEncoder<AddressedEnvelope<M,InetSocketAddress>>ctx - the ChannelHandlerContext which this MessageToMessageEncoder belongs tomsg - the message to encode to an other oneout - the List into which the encoded msg should be added
needs to do some kind of aggregationException - is thrown if an error occurspublic void bind(ChannelHandlerContext ctx, SocketAddress localAddress, ChannelPromise promise) throws Exception
ChannelOutboundHandlerAdapterChannelOutboundInvoker.bind(SocketAddress, ChannelPromise) to forward
to the next ChannelOutboundHandler in the ChannelPipeline.
Sub-classes may override this method to change behavior.bind in interface ChannelOutboundHandlerbind in class ChannelOutboundHandlerAdapterctx - the ChannelHandlerContext for which the bind operation is madelocalAddress - the SocketAddress to which it should boundpromise - the ChannelPromise to notify once the operation completesException - thrown if an error occurspublic void connect(ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise promise) throws Exception
ChannelOutboundHandlerAdapterChannelOutboundInvoker.connect(SocketAddress, SocketAddress, ChannelPromise) to forward
to the next ChannelOutboundHandler in the ChannelPipeline.
Sub-classes may override this method to change behavior.connect in interface ChannelOutboundHandlerconnect in class ChannelOutboundHandlerAdapterctx - the ChannelHandlerContext for which the connect operation is maderemoteAddress - the SocketAddress to which it should connectlocalAddress - the SocketAddress which is used as source on connectpromise - the ChannelPromise to notify once the operation completesException - thrown if an error occurspublic void disconnect(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception
ChannelOutboundHandlerAdapterChannelOutboundInvoker.disconnect(ChannelPromise) to forward
to the next ChannelOutboundHandler in the ChannelPipeline.
Sub-classes may override this method to change behavior.disconnect in interface ChannelOutboundHandlerdisconnect in class ChannelOutboundHandlerAdapterctx - the ChannelHandlerContext for which the disconnect operation is madepromise - the ChannelPromise to notify once the operation completesException - thrown if an error occurspublic void close(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception
ChannelOutboundHandlerAdapterChannelOutboundInvoker.close(ChannelPromise) to forward
to the next ChannelOutboundHandler in the ChannelPipeline.
Sub-classes may override this method to change behavior.close in interface ChannelOutboundHandlerclose in class ChannelOutboundHandlerAdapterctx - the ChannelHandlerContext for which the close operation is madepromise - the ChannelPromise to notify once the operation completesException - thrown if an error occurspublic void deregister(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception
ChannelOutboundHandlerAdapterChannelOutboundInvoker.deregister(ChannelPromise) to forward
to the next ChannelOutboundHandler in the ChannelPipeline.
Sub-classes may override this method to change behavior.deregister in interface ChannelOutboundHandlerderegister in class ChannelOutboundHandlerAdapterctx - the ChannelHandlerContext for which the close operation is madepromise - the ChannelPromise to notify once the operation completesException - thrown if an error occurspublic void read(ChannelHandlerContext ctx) throws Exception
ChannelOutboundHandlerAdapterChannelHandlerContext.read() to forward
to the next ChannelOutboundHandler in the ChannelPipeline.
Sub-classes may override this method to change behavior.read in interface ChannelOutboundHandlerread in class ChannelOutboundHandlerAdapterExceptionpublic void flush(ChannelHandlerContext ctx) throws Exception
ChannelOutboundHandlerAdapterChannelHandlerContext.flush() to forward
to the next ChannelOutboundHandler in the ChannelPipeline.
Sub-classes may override this method to change behavior.flush in interface ChannelOutboundHandlerflush in class ChannelOutboundHandlerAdapterctx - the ChannelHandlerContext for which the flush operation is madeException - thrown if an error occurspublic void handlerAdded(ChannelHandlerContext ctx) throws Exception
ChannelHandlerAdapterhandlerAdded in interface ChannelHandlerhandlerAdded in class ChannelHandlerAdapterExceptionpublic void handlerRemoved(ChannelHandlerContext ctx) throws Exception
ChannelHandlerAdapterhandlerRemoved in interface ChannelHandlerhandlerRemoved in class ChannelHandlerAdapterExceptionpublic void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception
ChannelHandlerAdapterChannelHandlerContext.fireExceptionCaught(Throwable) to forward
to the next ChannelHandler in the ChannelPipeline.
Sub-classes may override this method to change behavior.exceptionCaught in interface ChannelHandlerexceptionCaught in class ChannelHandlerAdapterExceptionpublic boolean isSharable()
ChannelHandlerAdapterisSharable in class ChannelHandlerAdapterCopyright © 2008–2025 The Netty Project. All rights reserved.