Socket Input-/Outputstream

Discussion in 'Java' started by Thomas, Dec 22, 2004.

  1. Thomas

    Thomas Guest

    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
    Thomas, Dec 22, 2004
    #1
    1. Advertising

  2. Thomas

    ByteCoder Guest

    Thomas wrote:
    > 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!

    --
    -------------
    - ByteCoder - ...I see stupid people
    -------------
    Curiosity *Skilled* the cat
    ByteCoder, Dec 22, 2004
    #2
    1. Advertising

  3. Thomas

    Ryan Stewart Guest

    "Thomas" <> wrote in message
    news:cqcrat$g38$...
    > 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.
    Ryan Stewart, Dec 23, 2004
    #3
  4. Thomas wrote:
    > 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
    Steve Horsley, Dec 23, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. puretec

    Socket: Input/OutputStream

    puretec, Dec 22, 2004, in forum: Java
    Replies:
    0
    Views:
    310
    puretec
    Dec 22, 2004
  2. Replies:
    6
    Views:
    1,193
  3. Replies:
    2
    Views:
    3,572
  4. Replies:
    2
    Views:
    590
  5. Laszlo Nagy
    Replies:
    1
    Views:
    4,767
    Mark Wooding
    Jan 27, 2009
Loading...

Share This Page