java – Selector. Close() close all client sockets?

I'm new to NiO sockets. I wrote a server using NiO sockets. Now I'm trying to write shutdown hook to ensure graceful exit by cleaning up resources

My question is selector Close() method closes all client sockets? If not, please tell me how to access all client sockets without listing them separately

Java doc says follow selector Close() method

The above description uses the word "deregistered", which gives the impression that it will not close sockets, but just delete their mappings from the selector

Solution

No, it just closes the selector

Before closing the selector, you can use the selector Keys() accesses all registered socket keys

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>