关闭 Netty UDP 服务器

发布于 2024-08-23 21:29:54 字数 541 浏览 4 评论 0原文

我使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

九厘米的零° 2024-08-30 21:29:54

netty提供了很多设置服务器的入口点,我不知道你用过哪一个。

您应该能够简单地 .unbind (或 .close)从 ServerBootstrap.bind

netty 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) the Channel you get back from ServerBootstrap.bind

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文