Java: how to communicate with multiple clients in a single thread

I have a list of sockets belonging to a single thread But I wonder if there is a feasible way to communicate (read / write) with those customers? I don't want to create a thread for each client because there may be too many users and it may be too expensive to create a thread for each client

Solution

I would say NiO is your best choice Check out one of the many excellent tutorials on NiO communication through sockets (well, socketchannel)!

I believe this is the tutorial I used when learning NiO: http://rox-xmlrpc.sourceforge.net/niotut/

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
分享
二维码
< <上一篇
下一篇>>