AndroidSocketClient icon indicating copy to clipboard operation
AndroidSocketClient copied to clipboard

3.0.1 版本 SocketInputReader.java 算法修正

Open lhb109163 opened this issue 5 years ago • 0 comments

原来的代码如下 int c;

            int matchIndex = 0;

            while (-1 != (c = this.inputStream.read())) {
                list.add((byte) c);
                if (c == (0xff & data[matchIndex])) {
                    matchIndex++;
                }
                else {
                        matchIndex = 0;
                }

                if (matchIndex == data.length) {
                    break;
                }
            }

当接收数据的正文 含有包尾数据的头部时会触发不了OnResponse 应更改如下 int c;

            int matchIndex = 0;

            while (-1 != (c = this.inputStream.read())) {
                list.add((byte) c);
                if (c == (0xff & data[matchIndex])) {
                    matchIndex++;
                }
                else {
                    if(c==(0xff & data[0]))
                        matchIndex=1;
                    else
                        matchIndex = 0;
                }

                if (matchIndex == data.length) {
                    break;
                }
            }

lhb109163 avatar Dec 01 '20 08:12 lhb109163