0

与服务器的部分连接完成,但不能总是从输入流中读取数据,只能读取一次。

    public void startSSLClient() throws IOException {
    inf = new Inflater();
    mSocketBufferReader = new BufferedReader(new InputStreamReader(mSslSocket.getInputStream()));
    new Thread() {
        boolean online =false;
        String s;
        @Override
        public void run() {
            try {
                while ( true ) {
                    String str = mSocketBufferReader.readLine();
                    if (!TextUtils.isEmpty(str)) {
                        Logger.e("PacketReader","process packet : "+str);
                    }
                }
            }
            catch (Exception e) {
                System.out.println("Error: " + e);
            }
        }
    }.start();
}

如果我尝试这个,它总是从输入流中读取。

    public void startSSLClient() throws IOException {
    inf = new Inflater();

    new Thread() {
        boolean online =false;
        String s;
        @Override
        public void run() {
            try {
                while ( true ) {
                    BufferedReader mSocketBufferReader = new BufferedReader(new InputStreamReader(mSslSocket.getInputStream()));
                    String str = mSocketBufferReader.readLine();
                    if (!TextUtils.isEmpty(str)) {
                        Logger.e("PacketReader","process packet : "+str);
                    }
                }
            }
            catch (Exception e) {
                System.out.println("Error: " + e);
            }
        }
    }.start();
}

我不知道原因。我只想使用一个全局字段。我不想总是使用新的本地字段。

4

1 回答 1

0
 BufferedReader mSocketBufferReader = new BufferedReader(new InputStreamReader(mSslSocket.getInputStream()));

把它排除在外。对于连接,您只能执行一次该语句。

于 2016-09-30T07:32:57.937 回答