ByteArrayOutputStream baos=new ByteArrayOutputStream(); DataOutputStream dos=new DataOutputStream(baos); try { dos.writeByte(1); dos.writeShort(1); dos.writeInt(1); dos.writeUTF("aaa"); byte[] info=baos.toByteArray(); socket.writeUtf(info); dos.close(); baos.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }