M - the type of message to be encodedpublic class DatagramPacketEncoder<M> extends MessageToMessageEncoder<io.netty.channel.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.| Constructor and Description |
|---|
DatagramPacketEncoder(MessageToMessageEncoder<? super M> encoder)
Create an encoder that encodes the content in
AddressedEnvelope to DatagramPacket using
the specified message encoder. |
| Modifier and Type | Method and Description |
|---|---|
boolean |
acceptOutboundMessage(Object msg)
Returns
true if the given message should be handled. |
void |
bind(io.netty.channel.ChannelHandlerContext ctx,
SocketAddress localAddress,
io.netty.channel.ChannelPromise promise) |
void |
close(io.netty.channel.ChannelHandlerContext ctx,
io.netty.channel.ChannelPromise promise) |
void |
connect(io.netty.channel.ChannelHandlerContext ctx,
SocketAddress remoteAddress,
SocketAddress localAddress,
io.netty.channel.ChannelPromise promise) |
void |
deregister(io.netty.channel.ChannelHandlerContext ctx,
io.netty.channel.ChannelPromise promise) |
void |
disconnect(io.netty.channel.ChannelHandlerContext ctx,
io.netty.channel.ChannelPromise promise) |
protected void |
encode(io.netty.channel.ChannelHandlerContext ctx,
io.netty.channel.AddressedEnvelope<M,InetSocketAddress> msg,
List<Object> out)
Encode from one message to an other.
|
void |
exceptionCaught(io.netty.channel.ChannelHandlerContext ctx,
Throwable cause) |
void |
flush(io.netty.channel.ChannelHandlerContext ctx) |
void |
handlerAdded(io.netty.channel.ChannelHandlerContext ctx) |
void |
handlerRemoved(io.netty.channel.ChannelHandlerContext ctx) |
boolean |
isSharable() |
void |
read(io.netty.channel.ChannelHandlerContext ctx) |
writepublic 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<io.netty.channel.AddressedEnvelope<M,InetSocketAddress>>Exceptionprotected void encode(io.netty.channel.ChannelHandlerContext ctx,
io.netty.channel.AddressedEnvelope<M,InetSocketAddress> msg,
List<Object> out)
throws Exception
MessageToMessageEncoderencode in class MessageToMessageEncoder<io.netty.channel.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(io.netty.channel.ChannelHandlerContext ctx,
SocketAddress localAddress,
io.netty.channel.ChannelPromise promise)
throws Exception
bind in interface io.netty.channel.ChannelOutboundHandlerbind in class io.netty.channel.ChannelOutboundHandlerAdapterExceptionpublic void connect(io.netty.channel.ChannelHandlerContext ctx,
SocketAddress remoteAddress,
SocketAddress localAddress,
io.netty.channel.ChannelPromise promise)
throws Exception
connect in interface io.netty.channel.ChannelOutboundHandlerconnect in class io.netty.channel.ChannelOutboundHandlerAdapterExceptionpublic void disconnect(io.netty.channel.ChannelHandlerContext ctx,
io.netty.channel.ChannelPromise promise)
throws Exception
disconnect in interface io.netty.channel.ChannelOutboundHandlerdisconnect in class io.netty.channel.ChannelOutboundHandlerAdapterExceptionpublic void close(io.netty.channel.ChannelHandlerContext ctx,
io.netty.channel.ChannelPromise promise)
throws Exception
close in interface io.netty.channel.ChannelOutboundHandlerclose in class io.netty.channel.ChannelOutboundHandlerAdapterExceptionpublic void deregister(io.netty.channel.ChannelHandlerContext ctx,
io.netty.channel.ChannelPromise promise)
throws Exception
deregister in interface io.netty.channel.ChannelOutboundHandlerderegister in class io.netty.channel.ChannelOutboundHandlerAdapterExceptionpublic void read(io.netty.channel.ChannelHandlerContext ctx)
throws Exception
read in interface io.netty.channel.ChannelOutboundHandlerread in class io.netty.channel.ChannelOutboundHandlerAdapterExceptionpublic void flush(io.netty.channel.ChannelHandlerContext ctx)
throws Exception
flush in interface io.netty.channel.ChannelOutboundHandlerflush in class io.netty.channel.ChannelOutboundHandlerAdapterExceptionpublic void handlerAdded(io.netty.channel.ChannelHandlerContext ctx)
throws Exception
handlerAdded in interface io.netty.channel.ChannelHandlerhandlerAdded in class io.netty.channel.ChannelHandlerAdapterExceptionpublic void handlerRemoved(io.netty.channel.ChannelHandlerContext ctx)
throws Exception
handlerRemoved in interface io.netty.channel.ChannelHandlerhandlerRemoved in class io.netty.channel.ChannelHandlerAdapterExceptionpublic void exceptionCaught(io.netty.channel.ChannelHandlerContext ctx,
Throwable cause)
throws Exception
exceptionCaught in interface io.netty.channel.ChannelHandlerexceptionCaught in class io.netty.channel.ChannelHandlerAdapterExceptionpublic boolean isSharable()
isSharable in class io.netty.channel.ChannelHandlerAdapterCopyright © 2008–2019 The Netty Project. All rights reserved.