client-server communication

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • stmfc
    New Member
    • May 2007
    • 65

    client-server communication

    in a server client communication which uses Socket and ServerSocket classes of java, think that client is sending some information byte by byte,
    and server is reading in the same way (byte by byte), then replies.

    what i cannot figure out is: when does the server start reading the bytes which are sent by client.
    does it wait until all bytes arrived?
    or does it immediately read when 1 byte is written to the related port.

    or does this behaviour is determined by the streams used in communication
    (DataInputstrea m, DataOutputStrea m etc...)?

    or is it about flushing? (some streams may have auto flush or something like that)
  • Nepomuk
    Recognized Expert Specialist
    • Aug 2007
    • 3111

    #2
    Originally posted by stmfc
    in a server client communication which uses Socket and ServerSocket classes of java, think that client is sending some information byte by byte,
    and server is reading in the same way (byte by byte), then replies.

    what i cannot figure out is: when does the server start reading the bytes which are sent by client.
    does it wait until all bytes arrived?
    or does it immediately read when 1 byte is written to the related port.

    or does this behaviour is determined by the streams used in communication
    (DataInputstrea m, DataOutputStrea m etc...)?

    or is it about flushing? (some streams may have auto flush or something like that)
    I don't know, if it's so with all Streams, but I've made the experience, that when I send Byte per Byte with something like
    [CODE=java]
    byte[] bytes = new byte[1024];
    // Fill the byte array...
    outputStream.wr ite(bytes);
    [/CODE]and receive with something like
    [CODE=java]
    byte[] bytes = new byte[1024];
    inputStream.rea d(bytes);
    [/CODE]I have correct data for quite a while, but at some point it starts to only have 0 0 0... What I do is, I wait, until the appropriate amount of Bytes are available with
    [CODE=java]
    while(inputStre am.available < 1024)
    {
    try{Thread.slee p(1);}
    catch(Exception e){e.printStack Trace();}
    }
    [/CODE]and then read the array in. Of course, that can be done with single bytes too.

    Greetings,
    Nepomuk

    Comment

    Working...