Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have a list of sockets that belongs to a single thread. But I wonder is there a feasible way to communicate (read/write from/to) with those those clients? I don't want to create one thread for each client because there may be too much users and creating one thread for each of them may be too costly.

like image 632
suat Avatar asked May 03 '26 02:05

suat


1 Answers

I'd say NIO is your best bet here. Check out one of the many good tutorials for NIO communications over a socket (well, SocketChannel)!

I believe this is the tutorial that I used when I had to learn NIO: http://rox-xmlrpc.sourceforge.net/niotut/

like image 107
claymore1977 Avatar answered May 05 '26 15:05

claymore1977



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!