开发者

Closing down a Netty UDP Server

开发者 https://www.devze.com 2022-12-21 21:32 出处:网络
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.

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(Exe开发者_JS百科cutors.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));


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号