Java NIO sockets?
Hi guys I have a question about the Java Nio socket api.
So I'm making a MMO game server and want to use Nio sockets on the server side so I don't have to create a thread for each client that connects. What I'm wondering is if it is fine to just use regular java.net sockets for the client instead of Nio for simplicity and since the client only needs one thread for receiving. I tested this and it worked fine but wanted some advice from someone more experienced using the Nio api.
Re: Java NIO sockets?
I created a limited function HTTP server using Selector. The chief advantage was that I did not have to create a thread to wait on inbound traffic from each open socket; the Selector handled that for me. It waits for activity on at least one socket and then "wakes up". This is very useful when dealing with long-lived connections with intermittent sends. Another application I worked on used non-blocking sockets with a polling loop. This is the Selector concept without the Selector, you handle testing the sockets yourself. If you are serious about your app, I suggest looking at SocketChannel, ServerSocketChannel, Selector, ThreadPoolExecutor, and non-blocking sockets. The learning curve is steep, but implementing is easy, once your figure out how all the parts work together.