-1
我運行這段代碼並且沒問題,但是我得到了每5秒或更多秒的輸出(比如它被阻塞),而它應該每秒多次;線的大小(dati)是可變的。Java讀取套接字Tcp更快
Socket clientSocket = new Socket("localhost", 5333);
PrintStream wr = new PrintStream(clientSocket.getOutputStream());
wr.println("sub");
InputStreamReader ir = new InputStreamReader(clientSocket.getInputStream());
BufferedReader br = new BufferedReader(ir);
String dati;
while ((dati = br.readLine()) != null){
System.out.println(dati);
}
我不知道會發生什麼,如果沒有行終止符被髮送,並最終,一些內部緩衝區填滿? –