0

I'm trying to create a very basic asynchronous server in Java (similar to http://msdn.microsoft.com/en-us/library/fx6588te.aspx in C#). All of the libraries I've seen for Java are way too complex for what I need and I'm wondering if there are any libraries that are simple and have a syntax similar to the C# example.

Edit: Why does plain sockets require root access to listen on the loopback, but nio doesn't require root?

  • 2
    would be good if you can spell out the requirements rather than making us read that link of yours. – Bhaskar Oct 01 '11 at 18:22
  • Have you seen this tutorial? : ["Writing the Server Side of a Socket"](http://download.oracle.com/javase/tutorial/networking/sockets/clientServer.html) –  Oct 01 '11 at 18:23
  • Yup, but for concurrent connections, that tutorial recommends using a thread per socket... but that leads in to the link in the second answer. –  Oct 01 '11 at 18:33

2 Answers2

2

try AsynchronousServerSocketChannel & AsynchronousSocketChannel

irreputable
  • 44,725
  • 9
  • 65
  • 93
1

This sounds like a job for Java's NIO (New I/O) ServerSocketChannel.

Be forewarned, though: this doesn't guarantee better performance. See:

Community
  • 1
  • 1
Matt Ball
  • 354,903
  • 100
  • 647
  • 710
  • 1
    Well I guess one thread per socket may just be the way to go, it seems. I'll write it using the threading then try nio to compare it. –  Oct 01 '11 at 18:38
  • Also, I just noticed that using a plain socket to listen to loopback requires root access, yet NIO doesn't require it... Is that normal? –  Oct 01 '11 at 18:41