关闭 Netty UDP 服务器
我使用 Netty 编写了一个非常简单的 UDP 服务器 - 它很高兴地绑定自身并接受消息,但我不知道如何解除它的绑定。
我是否遗漏了什么,或者 Netty 没有公开必要的 API 来取消绑定服务器?
编辑
这是我用来绑定服务器的代码:
DatagramChannelFactory f = new NioDatagramChannelFactory(Executors.newCachedThreadPool());
ConnectionlessBootstrap b = new ConnectionlessBootstrap(f);
ChannelPipeline p = b.getPipeline();
p.addLast("encoder", new StringEncoder());
p.addLast("decoder", new StringDecoder());
p.addLast("logic", this);
chan = b.bind(new InetSocketAddress(port));
I have a written a very simple UDP Server using Netty - it quite happily binds itself and accepts messages, but I can'y figure out how to unbind it.
Am I missing something, or does Netty not expose the necessary APIs to unbind a server?
Edit
Here is the code I am using to bind the server:
DatagramChannelFactory f = new NioDatagramChannelFactory(Executors.newCachedThreadPool());
ConnectionlessBootstrap b = new ConnectionlessBootstrap(f);
ChannelPipeline p = b.getPipeline();
p.addLast("encoder", new StringEncoder());
p.addLast("decoder", new StringDecoder());
p.addLast("logic", this);
chan = b.bind(new InetSocketAddress(port));
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
netty提供了很多设置服务器的入口点,我不知道你用过哪一个。
您应该能够简单地
.unbind
(或 .close)从 ServerBootstrap.bindnetty provides many entry points to setting up a server, I don't know which one you've used.
You should be able to simply
.unbind
(or .close) theChannel
you get back from ServerBootstrap.bind