第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Java Socket為什么服務(wù)器無法回復(fù)客戶端

Java Socket為什么服務(wù)器無法回復(fù)客戶端

慕妹3146593 2019-07-31 11:05:17
Java Socket為什么服務(wù)器無法回復(fù)客戶端我想寫代碼讓客戶端發(fā)送一個字符串給Server,Server打印字符串并回復(fù)一個字符串,然后Client打印字符串Server reply。我的服務(wù)器public class Server {public static void main(String[] args) throws IOException {     ServerSocket ss = null;     Socket s = null;     try {         ss = new ServerSocket(34000);         s = ss.accept();         BufferedReader in = new BufferedReader(new InputStreamReader(                 s.getInputStream()));         OutputStreamWriter out = new OutputStreamWriter(s.getOutputStream());         while (true) {             String string = in.readLine();             if (string != null) {                 System.out.println("br: " + string);                 if (string.equals("end")) {                     out.write("to end");                     out.flush();                     out.close();                     System.out.println("end");                     // break;                 }             }         }     } catch (IOException e) {         e.printStackTrace();     } finally {         s.close();         ss.close();     }}}我的客戶:public class Client {public static void main(String[] args) {     Socket socket =null;     try {         socket = new Socket("localhost", 34000);         BufferedReader in =new BufferedReader(new InputStreamReader(socket.getInputStream()));         OutputStreamWriter out = new OutputStreamWriter(socket.getOutputStream());         String string = "";         string = "end";         out.write(string);         out.flush();         while(true){             String string2 = in.readLine();             if(string2.equals("to end")){                 System.out.println("yes sir");                 break;             }         }     }  catch (Exception e) {         e.printStackTrace();     }finally{         try {             System.out.println("closed client");             socket.close();         } catch (IOException e) {             e.printStackTrace();         }     }}}有什么事嗎?如果我在客戶端類中刪除代碼“while(true)...”,那就沒問題。
查看完整描述

3 回答

?
慕神8447489

TA貢獻1780條經(jīng)驗 獲得超1個贊

你正在讀行,但你不是在寫行。添加換行符或致電BufferedReader.newLine().


查看完整回答
反對 回復(fù) 2019-07-31
  • 3 回答
  • 0 關(guān)注
  • 692 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號