消息未完全

时间:2016-08-08 11:28:38

标签: java

我需要获得完整的消息,例如Hello How are you。但是使用此代码,我只得到Hello

public class Messages{
    private static final int MTYPE = 0;
    private static final int FLAGS = 1;
    private static final int SEQUENCE = 2;
    private static final int CHAR1 = 3;
    private static final int CHAR2 = 4;
    private static final int CHAR3 = 5;
    private static final int CHAR4 = 6;
    private static final int CHAR5 = 7;

    private int type = 0;
    private boolean ack = false;
    private boolean isLastTelegram = false;
    private boolean isUTF8 = false;
    private int sequence = 0;
    private String messagePart = "";

    public InMsgTelegramm(byte[] msg) {

        type = msg[MTYPE] & 0xFF;

        sequence = msg[SEQUENCE] & 0xFF;

        int ackbyte = (int) ((msg[FLAGS] >> 7) & 1);

        ack = ackbyte != 0;

        int isLastTelegrambyte = (int) ((msg[FLAGS] >> 6) & 1);

        isLastTelegram = isLastTelegrambyte != 0;

        int isUTF8byte = (int) ((msg[FLAGS] >> 5) & 1);

        isUTF8 = isUTF8byte != 0;

        messagePart += (char) msg[CHAR1];
        messagePart += (char) msg[CHAR2];
        messagePart += (char) msg[CHAR3];
        messagePart += (char) msg[CHAR4];
        messagePart += (char) msg[CHAR5];
    }

messagePart包含5个字符Hello。它不是一个循环。 msg是一个字节数组,它接受字符串Hello How are you,但最后我得到输出为Hello

除序列之外的其余参数对于消息保持相同。我如何获得完整的信息?

0 个答案:

没有答案
相关问题