dcsimg
To send binary data with variable lenght across TCP, I dont know if I must use an InputStream or object serialization. Can you help me?
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Thursday, April 25, 2002 08:59 AM

I must send via TCP/IP a packet that can containts more than 64 kbits. It has a variable length and I must analyse it at the level of bits since it can be formed by a different number of fields from a time to another and the length of these fields can be different. For example, I must check if bit 32th is 0 or is 1, or if the eight first bits are 00h or FFh. I have made several test programs to send an String or an serialized object by means of TCP/IP and they work, buy I thing that they are not useful to receive the packets that I need at this application. 1) If I use an InputStream, the code to receive an String is : ... BufferedReader in = new BufferedReader ( new I   More>>

I must send via TCP/IP a packet that can containts more than 64 kbits. It has a variable length and I must analyse it at the level of bits since it can be formed by a different number of fields from a time to another and the length of these fields can be different. For example, I must check if bit 32th is 0 or is 1, or if the eight first bits are 00h or FFh.


I have made several test programs to send an String or an serialized object by means of TCP/IP and they work, buy I thing that they are not useful to receive the packets that I need at this application.



1) If I use an InputStream, the code to receive an String is :



...

BufferedReader in = new BufferedReader (

new InputStreamReader (clientSocket.getInputStream()));

String inputLine;

while ((inputLine = in.readLine()) != null)

{

// I proccess here the incoming line.

...

}

...


PROBLEM: The combination of bits that arrive can be interpreted as an end of line at several positions.




2) If I use an BufferedInputStream, that is, objects, the code to receive an object is:



...

try

{

obj=ooi.readObject();

objAS = (MyObjectClass)obj;

ooi.close();

}

catch(Exception ex)

{

...

}



// Here, I proccess the received object.


PROBLEM: I must declare the class MyObjectClass, but I dont know what
is the length of the waited object (it can be, for example, 87 bits or
89 bits).



Please, can you say me if I must use InputStreams or serialized objects and what is the type of data that I must declare.



Many thanks.

   <<Less
About | Sitemap | Contact