• Post Reply Bookmark Topic Watch Topic
  • New Topic

Bunch of NIO questions

 
Daniil Sosonkin
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I'm fairly new to NIO, but I do see its benefits. Yet, I still have some questions regarding real world use. For starters, if you drop all advertizements and sale points and theory - how much better is it? has anyone rewritten multiclient socket apps and seen dramatic performance improvements?

Also, I have this server that sends out streaming data to the client after some negotiation. At this moment, it spawns new thread for each client, so I'm thinking to converting it to NIO to allow for more clients. But there are few questions. When client connects, it sends username/password etc, server reads it, responds with some extra information and registers client for streaming data. After that, there are no more reads, just writes of data to the client as soon as another thread submits new information. But, when client needs to modify stream somehow or do something else, it connects again and does some communication (while data is sent on another socket).

So I was thinking how client processing should work. To me, I see no other way as allocating a separate thread. But since the communication is short lived, the thread isn't running too long and I dont see 4000 clients logging in at the same time. But serving 4000 clients is possible.

Due to that, I was thinking to use Piped I/O to send newly read data from client when communicating. Does this makes sense?

But here are some questions.

How do I detect what client closed its connection prematuraly?
What do I do when I get an exception from SocketChannel.write(ByteBuffer)?
What do I do when method above doesn't write all data?
Is there a timeout on async sockets?

I hope this makes and hope someone has an answer those tutorials online somewhat confusing.

Thanx
 
Guy Allard
Ranch Hand
Posts: 776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have absolutely no practical experience with this, although the questions (and answers whatever they are) are very interesting.

Have you looked at:

NIO Nonblocking Socket Example

Guy
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!