try {
headdata = headstr.getBytes("ISO-8859-1");
} catch (UnsupportedEncodingException e) {}
ByteBuffer buffer = ByteBuffer.wrap(new byte[headdata.length + contentLen]);
buffer.clear();
buffer.put(headdata);
buffer.put(cmdtype);
for(int i=0; i<outMessages.length; i++) {
buffer.putShort((short) outMessages[i].getBody().length);
buffer.put(outMessages[i].getBody());