Help Needed to Implement Streams in NIO

I want to create a NIOServer that reads data from a client using 1 thread and writes data to the client using a different thread. also accepting client connection will be in some other thread.

Is there an online help

Thanks Deepak

+1


a source to share


3 answers


Why use so many streams when you make it all easier with a selector and a single stream? If you want to take a multi-threaded approach to network I / O, you should consider plain old blocking sockets.

By the way, you can do everything with three selectors: one accepts connections, one reads, and one writes. When you accept a connection, you can register a channel with two other selectors with matching interests.



Of course, when you have to free a channel, you must deselect the SelectionKey from both selectors (read and write), or close it.

+1


a source


I suggest you check out the sample code that comes with the JDK under sample / nio / server



0


a source


I would recommend Apache Mina to you : very flexible, high level abstraction, high performance, etc.

0


a source







All Articles