Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: I/O question..

  1. #1
    Member
    Join Date
    May 2010
    Posts
    39
    Thanks
    4
    Thanked 3 Times in 3 Posts

    Arrow I/O question..

    hello folks.

    Small question, pain in my ass.

    Anyway, the reason i've asked this question is due to this sample code,

    Client sided:
    			output.write(packet.getId());
    			output.write((packet.getBuffer().length >>> 24) & 0xFF);
    			output.write((packet.getBuffer().length >>> 16) & 0xFF);
    			output.write((packet.getBuffer().length >>> 8) & 0xFF);
    			output.write((packet.getBuffer().length >>> 0) & 0xFF);
    			output.write(packet.getBuffer());

    Packet, is a wrapper i use to help me construct packets,

    public Packet(int id, byte[] buffer);

    Well, to make sure im writing the correct byte, i check the length, within the method.
    System.out.println(packet.getBuffer().length);

    Now an example client code:
    System.out.println(input.availible());

    Now' ill get significantly smaller numbers in comparison..

    The server will write a byte array of 160291 bytes(Confirmed by outprint), and the clien will read somthing like 17391 as avail,

    *Other notes,

    After I call the reading off all the avail bytes, the input fills up with another byte array with another substansilly small amount of the buffer size, eventually all the incoming byte array's lengths add up to the amount of bytes I sent in the first place,

    This means:

    **I can work around this small pain, but Im just curious why the input stream isn't being filled with in the 160291 byte's in the first read.

    The above is where my question lyes,

    All possible answers welcomed!
    Last edited by Time; November 3rd, 2010 at 09:07 PM.


  2. #2
    Member
    Join Date
    May 2010
    Posts
    39
    Thanks
    4
    Thanked 3 Times in 3 Posts

    Default Re: I/O question..

    Is there a limit to the amount of byte's the InputStream of a socket, can be filled up to at a current moment?

    I assumed the max was Integer.MAX_AMOUNT,

    Hmmm

  3. #3
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,372
    Thanks
    183
    Thanked 836 Times in 779 Posts
    Blog Entries
    5

    Default Re: I/O question..

    I'm confused about what's the client and what's the server...is the first snipped of code meant to be the server? Anyway, perhaps I misunderstand a little but since you write the id and the packet length to the output stream, then anything reading that stream will end up reading more bytes than the total bytes in the packets cumulative (eg (length and id) * packet cumulative)

  4. #4
    Member
    Join Date
    May 2010
    Posts
    39
    Thanks
    4
    Thanked 3 Times in 3 Posts

    Default Re: I/O question..

    First is the server, but either way it shouldnt matter right?, InputStream is still an InputStream,

    and me writing the id, and the length, shouldn't matter, it's not incorporated to the initial reading:
    byte[] data = new byte[input.available()];
    System.out.println(input.read(data));

    Shouldn't the incoming byte's equal to the bytes sent out?, hence my question on the incoming limit if any

  5. #5
    Member
    Join Date
    May 2010
    Posts
    39
    Thanks
    4
    Thanked 3 Times in 3 Posts

    Default Re: I/O question..

    Hmm, Im thinking has somthing to do with network, rather then inputStream itself, let me do some tests.