2 of 6 added 7 characters in body; edited title

Using an int variable as index in an array

I am putting together a fairly simple server that listens for a connection then creates this thread - textbook Java code - then accepts data on that connection.

I am following a protocol that the manufacturer has laid out for SOM and EOM as below. I then simply populate a byte array with using a byte counter.

I think this is the simplest doing so, and it seems to work fine. Is there any possible problem with taking this approach? I want to be sure using a bytecounter with an array is acceptable. I can't see anyway that bytecounter could get out of sync or anything like that. I like to keeps things simple. Is there anything wrong with this code?

//thread setup above
 int i = 0;
    int bytecounter = 0;

    byte[] inbyte = new byte[1024];

    byte b ;

while(true) {

int bytecounter = 0;


        while( ( b = disIn.readByte() ) !=  (byte)0xfe ){

            if( b == (byte)0xfd  ){

                inbyte = new byte[1024];
                inbyte[0] = b;
                bytecounter = 1;

            else {

                 inbyte[bytecounter] = b;



    }catch ( java.io.EOFException ioef ){
        System.out.println("EOF received" );

//do stuff with the inbyte[] data....

// and come back through the while(true) loop