Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

io vs nio debate continues  RSS feed

 
Alan Shiers
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI there,

I once created a client/server application and used ObjectInputStream and ObjectOutputStream to move the object data back and forth. This worked well. I'm now considering that since the client/server application will soon include VoiP and video streaming, that a faster server using NIO may help increase performance and help get rid of those herky-jerky video images.

My understanding of NIO is basic, at best, and only have an example from the Deitel book: Java How To Program that shows how to make a chat program. It works, but now I need to figure out how I it is I can move object data using NIO. How does one do that? How does one deconstruct an object and send it out the wire using ByteBuffer? Or some other buffer class? The way we did things before with the old io where you can choose a variety of stream types simply doesn't seem to apply to the NIO way of doing things.

Please advise. I'm confused.

Alan
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is an article about using SocketChannel and ServerSocketChannel. You can get a Channel to communicate with an ObjectInputStream or ObjectOutputStream using Channels.newInputStream() and Channels.newOutputStream().

I wouldn't expect a big performance difference from using NIO for this part of the code, though it may help. The two areas I'd expect the most noticeable gains are (a) handling a large number of concurrent users with a small number of threads, using a Selector, and (b) handling the streaming more efficiently by connecting a FileChannel to a SocketChannel using FileChannel's transferBytes() method. (Assuming the things you're streaming are stored in files.) It may take a while before you get all this working, and NIO is generallyl more complex to figure out than traditional IO is. But there are (or can be) big benefits. I just want you to know that you may not see them right away.
[ April 26, 2007: Message edited by: Jim Yingst ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!