我工作的資深項目,我想使用此代碼從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;
}
你知道什麼是一段時間的陳述嗎? – karim 2014-10-19 15:51:48