socket不断读取服务器输出的信息
in 默认分类 with 0 comment

socket不断读取服务器输出的信息

in 默认分类 with 0 comment
        String host = "XXX";
        int port = XXX;
        // 与服务端建立连接
        Socket socket = new Socket(host, port);
        InputStreamReader reader = new InputStreamReader(socket.getInputStream(), Charset.defaultCharset());
        BufferedReader bufferedReader = new BufferedReader(reader);
        String string;
        while ((string = bufferedReader.readLine()) != null) {
            System.out.println(string);
        }
Responses