quicksilverm28 wrote:
I have server which is receiving data from multiple clients. The data is not
standard protocol. Each client is sending bunch of binrary files .bin files
. The data is received by the server from each socket and written on the
file system for later processing.
I wanted to do stream I\O on this. Now, when I implemented NIO I am learning
this is a blocking call. Since the StreamIOHandler internally is writing the
bytes via messagereceived, I thought I would be able to see what exactly is
happening behind the scenes.

In the lab setup, what I see is that even though the NE is sending more than
1000 bytes ( which I get when I use StreamIOHandler), I see that
messageReceived gets 5 bytes. I think MINA gets back with 5 bytes since
thats what the socket might have, at the time. Question is how does other
NIO bases servers must be functioning ?
You will receive the 1000 bytes but not necessarily in a single ByteBuffer. The OS / network may split your data into several chunks and deliver those separately. If all you want is to save the bytes to a file, you could create the file in sessionOpened() and put a reference to the OutputStream as an attribute in the MINA Session. Then you just write() the data you receive in messageReceived() until all data has been received. Then you close to OutputStream. Since OutputStream.write() is a blocking operation you should probably use an ExecutorFilter to make sure the MINA IO thread isn't blocked when you write to your files.

Your other option would be implement a protocol codec. Have a look at the tutorials and the examples on this subject.

HTH

/Niklas

Reply via email to