Results 1 to 2 of 2
  1. #1
    tkblackbelt is offline Member
    Join Date
    Jan 2012
    Posts
    1
    Rep Power
    0

    Default 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.

    Thanks :)

  2. #2
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    7

    Default 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.

Similar Threads

  1. New to Java Sockets
    By Lord Josh 1 in forum Networking
    Replies: 1
    Last Post: 02-15-2011, 05:38 PM
  2. Java Sockets
    By PhQ in forum New To Java
    Replies: 2
    Last Post: 05-07-2010, 12:34 PM
  3. Request-Reply With Java Sockets
    By grassbl8d in forum Networking
    Replies: 0
    Last Post: 03-03-2010, 07:11 PM
  4. Java sockets
    By Camzie in forum NetBeans
    Replies: 3
    Last Post: 12-22-2009, 05:39 PM
  5. Java application using sockets!
    By rameshraj in forum Threads and Synchronization
    Replies: 1
    Last Post: 06-11-2008, 07:13 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •