473,414 Members | 1,948 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Reading data uisng NIO

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
1 2846
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Andy | last post by:
Hi, In the code below (not pretty I know but it's an early version :-P) I'm having problems reading the data object back in. If I move the reading code to immediately after the section where it...
1
by: Magnus | last post by:
allrite folks, got some questions here... 1) LAY-OUT OF REPORTS How is it possible to fundamentaly change the lay-out/form of a report in access? I dont really know it that "difficult", but...
6
by: KevinD | last post by:
assumption: I am new to C and old to COBOL I have been reading a lot (self teaching) but something is not sinking in with respect to reading a simple file - one record at a time. Using C, I am...
8
by: mrwoopey | last post by:
Hi, I need to get data from a client via a HL7 interface. How can I do this? Can I do this via visual basic? Please post, code, links, anything! Your help is appreciated! Phin
1
by: C | last post by:
Hi, Does anyone know of any sites that have sample code that shows how to export data to Excel using VS Tools for Office? What is the advantage of using VS Tools for Office over uisng Interop?...
1
by: thrikris | last post by:
I am trying to use a include file to include a whole bunch of text data in my source cpp file. This text data can change so I have to maintain it as a separate file and have something that works...
5
blazedaces
by: blazedaces | last post by:
Ok, so you know my problem, java is running out of memory reading with SAX, the event-based xml parser intended more-so than DOM for extremely large files. I'll try to explain what I've been doing...
6
by: efrenba | last post by:
Hi, I came from delphi world and now I'm doing my first steps in C++. I'm using C++builder because its ide is like delphi although I'm trying to avoid the vcl. I need to insert new features...
2
by: pnalla | last post by:
Hi, provide the connection string for mySql,oracle,Db2,sqlserver uisng C# please provide the code for above databses Thanks Prasad
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.