public class MBUDPClientInboundHandler
extends io.netty.channel.SimpleChannelInboundHandler<io.netty.buffer.ByteBuf>
本类的行为表现让Netty的UDP达到类似于TCP这样的“连接”效果(跟MINA里 的Session管理类似),从而简化基于Netty UDP的编程难度(Netty最新版框架 对于UDP的支持回归到了UDP的本质,也就是没做过多封装和支持,使得应用层 并没有从Netty框架上获得更多的易用性,而这只能MobileIMSDK框架netty版 自行实现和解决了)。
从某种意义上讲,Netty4中的UDP支持相对于MINA2来说,既是进步(没有做过多 封装,回归到了协议的本质),也是退步(让UDP裸奔,显然易用性上就没那么好 了)。
ServerCoreHandler
,
net.x52im.mobileimsdk.server.ServerLauncher#initGateWays()
构造器和说明 |
---|
MBUDPClientInboundHandler(ServerCoreHandler serverCoreHandler) |
限定符和类型 | 方法和说明 |
---|---|
void |
channelActive(io.netty.channel.ChannelHandlerContext ctx)
客户端与服务端建立“连接”时会调用本方法。
|
void |
channelInactive(io.netty.channel.ChannelHandlerContext ctx)
客户端与服务端断开“连接”时会调用本方法。
|
protected void |
channelRead0(io.netty.channel.ChannelHandlerContext ctx,
io.netty.buffer.ByteBuf bytebuf)
客户端向服务端发送数据时会调用本方法。
|
void |
exceptionCaught(io.netty.channel.ChannelHandlerContext ctx,
java.lang.Throwable e)
UDP“会话”处理过程中出现异步时会调用本方法。
|
channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, userEventTriggered
ensureNotSharable, handlerAdded, handlerRemoved, isSharable
public MBUDPClientInboundHandler(ServerCoreHandler serverCoreHandler)
public void exceptionCaught(io.netty.channel.ChannelHandlerContext ctx, java.lang.Throwable e)
因UDP是无连接协议,此处的“会话”只是逻辑层的扩展(类似于MINA中的 IoSession概念),并非真正的TCP中的“连接”或“会话”。
exceptionCaught
在接口中 io.netty.channel.ChannelHandler
exceptionCaught
在接口中 io.netty.channel.ChannelInboundHandler
exceptionCaught
在类中 io.netty.channel.ChannelInboundHandlerAdapter
public void channelActive(io.netty.channel.ChannelHandlerContext ctx) throws java.lang.Exception
因UDP是无连接协议,此处的“连接”只是逻辑层的扩展(类似于MINA中的 IoSession概念),并非真正的TCP中的“连接”或“会话”。
channelActive
在接口中 io.netty.channel.ChannelInboundHandler
channelActive
在类中 io.netty.channel.ChannelInboundHandlerAdapter
java.lang.Exception
public void channelInactive(io.netty.channel.ChannelHandlerContext ctx) throws java.lang.Exception
“断开”的原因有可能多种可能性:
因UDP是无连接协议,此处的“连接”只是逻辑层的扩展(类似于MINA中的 IoSession概念),并非真正的TCP中的“连接”或“会话”。
channelInactive
在接口中 io.netty.channel.ChannelInboundHandler
channelInactive
在类中 io.netty.channel.ChannelInboundHandlerAdapter
java.lang.Exception
protected void channelRead0(io.netty.channel.ChannelHandlerContext ctx, io.netty.buffer.ByteBuf bytebuf) throws java.lang.Exception
本方法是"客户端 to 服务端"这个方向的数据通信唯一处理方法。
channelRead0
在类中 io.netty.channel.SimpleChannelInboundHandler<io.netty.buffer.ByteBuf>
java.lang.Exception