fixed problem when packet length is greater than buffer size.
replaced manual loop for copying byte array with System.arraycopy