Basic Asyncronous TCP server in Java
I'm trying to create a very basic asynchronous server in Java (similar to http://msdn.microsof开发者_开发技巧t.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?
try AsynchronousServerSocketChannel & AsynchronousSocketChannel
This sounds like a job for Java's NIO (New I/O) ServerSocketChannel
.
Be forewarned, though: this doesn't guarantee better performance. See:
- Java in 2011: threaded sockets VS NIO: what to choose on 64bit OS and latest Java version?
- http://www.thebuzzmedia.com/java-io-faster-than-nio-old-is-new-again/
精彩评论