Results 1 to 2 of 2
Thread: Java NIO sockets?
- 01-13-2012, 05:57 PM #1Member
- Join Date
- Jan 2012
- Rep Power
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.
- 01-16-2012, 01:42 PM #2
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.The Java Tutorial. Read it.
- By Lord Josh 1 in forum NetworkingReplies: 1Last Post: 02-15-2011, 04:38 PM
- By PhQ in forum New To JavaReplies: 2Last Post: 05-07-2010, 11:34 AM
- By grassbl8d in forum NetworkingReplies: 0Last Post: 03-03-2010, 06:11 PM
- By Camzie in forum NetBeansReplies: 3Last Post: 12-22-2009, 04:39 PM
- By rameshraj in forum Threads and SynchronizationReplies: 1Last Post: 06-11-2008, 06:13 PM