开发者

Basic Asyncronous TCP server in Java

开发者 https://www.devze.com 2023-04-09 15:55 出处:网络
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

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/
0

精彩评论

暂无评论...
验证码 换一张
取 消