我正在处理高级项目,我尝试使用此代码从TCP套接字读取,但它一次从套接字读取,但我需要连续读数
任何提示 提前致谢! 这是代码:
class ClientAsyncTask extends AsyncTask<String, String, String> {
@Override
protected String doInBackground(String... params) {
String result = null;
try {
Socket socket = new Socket(params[0],
Integer.parseInt(params[1]));
InputStream is = socket.getInputStream();
PrintWriter out = new PrintWriter(socket.getOutputStream(),true);
out.println(params[2]);
BufferedReader br = new BufferedReader(
new InputStreamReader(is));
//Read data in the input buffer
result = br.readLine();
//Close the client socket
socket.close();
} catch (NumberFormatException e) {
e.printStackTrace();
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return result;
}
答案 0 :(得分:0)