By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,959 Members | 1,139 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,959 IT Pros & Developers. It's quick & easy.

Reading data uisng NIO

P: n/a
I have a problem in developing a NIO server for an existing clients. The
client application is distributed to our customers ( a j2ME client) and making
modifications to the client is not practical.
Basically, J2MEclient send data to our server :

DataOutputStream daos = new DataOutputStream( some stream);
daos.writeUTF("string 1");
daos.writeByte(4);
daos.writeInt(67);
daos.writeUTF("string2 ");
daos.writeUTF("string3 ");

Thats how the client send s the data and we wish to change our server to use NIO.
However, I can make only bytes read into a new buffer from the socket channel.

socketChannel.read( byteBuffer);

This buffer holds the data. How do i read a string, then a Byte, then an int and
next two strings. How do I know where does the string beign and where it ends.
Unless I know that, I wont be able to use Character encoder/decoder to retrive
the string the client sends
Jul 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Kiran Kumar wrote:
I have a problem in developing a NIO server for an existing clients. The
client application is distributed to our customers ( a j2ME client) and making
modifications to the client is not practical.
Basically, J2MEclient send data to our server :

DataOutputStream daos = new DataOutputStream( some stream);
daos.writeUTF("string 1");
daos.writeByte(4);
daos.writeInt(67);
daos.writeUTF("string2 ");
daos.writeUTF("string3 ");

Thats how the client send s the data and we wish to change our server to use NIO.
However, I can make only bytes read into a new buffer from the socket channel.

socketChannel.read( byteBuffer);

This buffer holds the data. How do i read a string, then a Byte, then an int and
next two strings. How do I know where does the string beign and where it ends.
Unless I know that, I wont be able to use Character encoder/decoder to retrive
the string the client sends


Once you have the data in a byte array, use a ByteArrayInputStream and
feed it to a DataInputStream and read the data exactly how you used to.

Ray
Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.