Socket Input-/Outputstream

T

Thomas

I have the following problem:


a java application (client) should communicate with a sever, where the

communication objects are as follows:


public class Comm_1

{

long lSync;

long lLength;

CData_1 oData1;

}


.....


public class Comm_1

{

long lSync;

long lLength; // length [byte] of the object

CData_n oDatan;

}


1) How can I determine the length of an object in order to assign that value

to o.lLength (I know how to do this by hand);


2) Is the ObjectOutputStream ( linked to the socket.getOutputStream() ) the

stream which I should use for sending the objects?


sincerely

thomas
 
B

ByteCoder

Thomas said:
I have the following problem:


a java application (client) should communicate with a sever, where the

communication objects are as follows:


public class Comm_1

{

long lSync;

long lLength;

CData_1 oData1;

}


....


public class Comm_1

{

long lSync;

long lLength; // length [byte] of the object

CData_n oDatan;

}


1) How can I determine the length of an object in order to assign that value

to o.lLength (I know how to do this by hand);

Object.length, Object.get...()? Could be anything. A proper IDE has code
completion. I think that is very helpful for these kind of questions.
2) Is the ObjectOutputStream ( linked to the socket.getOutputStream() ) the

stream which I should use for sending the objects?

I'd say so.

Good luck!
 
R

Ryan Stewart

Thomas said:
1) How can I determine the length of an object in order to assign that
value
to o.lLength (I know how to do this by hand);
You do? How exactly is that? There's no guarantee what size an object will
be, especially across different platforms.
 
S

Steve Horsley

Thomas said:
I have the following problem:


a java application (client) should communicate with a sever, where the

communication objects are as follows:


public class Comm_1

{

long lSync;

long lLength;

CData_1 oData1;

}


....


public class Comm_1

{

long lSync;

long lLength; // length [byte] of the object

CData_n oDatan;

}

You seem to have two different definitions for the same class here, which worries
me a bit. I strongly recommend that both ends of the connection use the same
class definition.
1) How can I determine the length of an object in order to assign that value

to o.lLength (I know how to do this by hand);


2) Is the ObjectOutputStream ( linked to the socket.getOutputStream() ) the

stream which I should use for sending the objects?
Don't worry about the length of objects - ObjectInputStream and
ObjectOutputStream do all of that stuff for you. Just write objects at one end,
and read them at the other end. It all happens as if by magic.

Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top