0
DataInputStream dis = new DataInputStream(s.getInputStream());
String Message = dis.readUTF();
History.setText(History.getText()+ '\n' + "Client:-" + Message);
System.out.println("Message from client :- "+ Message);
}
catch(IOException e) {
History.setText(History.getText()+ "\n" + "Error in Connection");
History.setText(History.getText()+ "\n" + "Please Try Again or Exit");
解決 現在能夠從客戶端和用戶無法得到的消息
對於初學者,我會在IOException捕獲塊中添加日誌記錄。也許某個地方正在拋出異常。另一個觀察 - DataInputStreams和DataOutputStreams沒有被關閉。你可以使用試用資源。 – Boris
「他們不能接收和發送來自對方的消息」是什麼意思?引發異常或服務器和客戶端開始等待,什麼都沒有發生? – dezhik
服務器和客戶端已成功連接,但客戶端和服務器都無法在單擊發送按鈕時收到對方的消息。 – kapoor