public class MBUDPServerChannel
extends io.netty.channel.nio.AbstractNioMessageChannel
implements io.netty.channel.socket.ServerSocketChannel
因Netty4.1.x中对UDP的实现相对于MINA这样的框架来说,回归到了UDP协议的本色状态 (即极简设计),从设计上、性能上来说回归到了协议的本质(这也是为什么Netty4中有 关UDP的官方Demo代码几乎没有的原因,因为没太多的东西可演示的)。但对于应用层开发 (比如IM、消息推送等场景)来说,失去了很多的便利性。因为为了客户端的身份识别、鉴 权、安全性等等,肯定是要做到“伪连接”的存在(MINA2中称为Session),这样就可以识别 客户端的身份、请求的合法性,并通过超时机制来达到客户端无故退出(比如崩溃等)时 自动判定“连接”的断开,从而即时更新此客户端的在线状态等。而Netty4中的这种“伪连接“、 ”伪连接超时检测机制“等,通通无法直接实现,要想达到这一点,那都得自已来。
NioServerSocketChannel的官方源码请见: NioServerSocketChannel
限定符和类型 | 字段和说明 |
---|---|
protected java.util.LinkedHashMap<java.net.InetSocketAddress,MBUDPChannel> |
channels |
限定符 | 构造器和说明 |
---|---|
|
MBUDPServerChannel() |
protected |
MBUDPServerChannel(java.nio.channels.DatagramChannel datagramChannel) |
限定符和类型 | 方法和说明 |
---|---|
io.netty.channel.socket.ServerSocketChannelConfig |
config() |
protected void |
doBind(java.net.SocketAddress localAddress) |
protected void |
doClose() |
protected boolean |
doConnect(java.net.SocketAddress addr1,
java.net.SocketAddress addr2) |
protected void |
doDisconnect() |
protected void |
doFinishConnect() |
protected int |
doReadMessages(java.util.List<java.lang.Object> list) |
protected boolean |
doWriteMessage(java.lang.Object msg,
io.netty.channel.ChannelOutboundBuffer buffer) |
boolean |
isActive()
判断监听是否已启动。
|
protected java.nio.channels.DatagramChannel |
javaChannel() |
java.net.InetSocketAddress |
localAddress() |
protected java.net.SocketAddress |
localAddress0() |
io.netty.channel.ChannelMetadata |
metadata() |
java.net.InetSocketAddress |
remoteAddress() |
protected java.net.SocketAddress |
remoteAddress0() |
void |
removeChannel(io.netty.channel.Channel channel)
将一个客户端的Channel实例从服务端管理的列表中移除。
|
closeOnReadError, continueOnWriteError, doBeginRead, doWrite, newUnsafe
clearReadPending, doDeregister, doRegister, eventLoop, isCompatible, isOpen, isReadPending, newDirectBuffer, newDirectBuffer, selectionKey, setReadPending, unsafe
alloc, bind, bind, bytesBeforeUnwritable, bytesBeforeWritable, close, close, closeFuture, compareTo, connect, connect, connect, connect, deregister, deregister, disconnect, disconnect, doShutdownOutput, equals, filterOutboundMessage, flush, hashCode, id, invalidateLocalAddress, invalidateRemoteAddress, isRegistered, isWritable, newChannelPipeline, newFailedFuture, newId, newProgressivePromise, newPromise, newSucceededFuture, parent, pipeline, read, toString, validateFileRegion, voidPromise, write, write, writeAndFlush, writeAndFlush
alloc, bytesBeforeUnwritable, bytesBeforeWritable, closeFuture, eventLoop, flush, id, isOpen, isRegistered, isWritable, parent, pipeline, read, unsafe
protected final java.util.LinkedHashMap<java.net.InetSocketAddress,MBUDPChannel> channels
public MBUDPServerChannel() throws java.io.IOException
java.io.IOException
protected MBUDPServerChannel(java.nio.channels.DatagramChannel datagramChannel)
public java.net.InetSocketAddress localAddress()
localAddress
在接口中 io.netty.channel.Channel
localAddress
在接口中 io.netty.channel.socket.ServerSocketChannel
localAddress
在类中 io.netty.channel.AbstractChannel
protected java.net.SocketAddress localAddress0()
localAddress0
在类中 io.netty.channel.AbstractChannel
public java.net.InetSocketAddress remoteAddress()
remoteAddress
在接口中 io.netty.channel.Channel
remoteAddress
在接口中 io.netty.channel.socket.ServerSocketChannel
remoteAddress
在类中 io.netty.channel.AbstractChannel
protected java.net.SocketAddress remoteAddress0()
remoteAddress0
在类中 io.netty.channel.AbstractChannel
public io.netty.channel.ChannelMetadata metadata()
metadata
在接口中 io.netty.channel.Channel
public io.netty.channel.socket.ServerSocketChannelConfig config()
config
在接口中 io.netty.channel.Channel
config
在接口中 io.netty.channel.socket.ServerSocketChannel
public boolean isActive()
isActive
在接口中 io.netty.channel.Channel
AbstractInterruptibleChannel.isOpen()
,
DatagramSocket#isBound()
protected java.nio.channels.DatagramChannel javaChannel()
javaChannel
在类中 io.netty.channel.nio.AbstractNioChannel
protected void doBind(java.net.SocketAddress localAddress) throws java.lang.Exception
doBind
在类中 io.netty.channel.AbstractChannel
java.lang.Exception
protected void doClose() throws java.lang.Exception
doClose
在类中 io.netty.channel.nio.AbstractNioChannel
java.lang.Exception
public void removeChannel(io.netty.channel.Channel channel)
channel
- 要移除的Channel引用protected int doReadMessages(java.util.List<java.lang.Object> list) throws java.lang.Exception
doReadMessages
在类中 io.netty.channel.nio.AbstractNioMessageChannel
java.lang.Exception
protected boolean doWriteMessage(java.lang.Object msg, io.netty.channel.ChannelOutboundBuffer buffer) throws java.lang.Exception
doWriteMessage
在类中 io.netty.channel.nio.AbstractNioMessageChannel
java.lang.Exception
protected boolean doConnect(java.net.SocketAddress addr1, java.net.SocketAddress addr2) throws java.lang.Exception
doConnect
在类中 io.netty.channel.nio.AbstractNioChannel
java.lang.Exception
protected void doFinishConnect() throws java.lang.Exception
doFinishConnect
在类中 io.netty.channel.nio.AbstractNioChannel
java.lang.Exception
protected void doDisconnect() throws java.lang.Exception
doDisconnect
在类中 io.netty.channel.AbstractChannel
java.lang.Exception