Re: [問題] Client接收String的問題

看板java作者 (Mr. Pan)時間14年前 (2011/09/12 00:48), 編輯推噓3(303)
留言6則, 4人參與, 最新討論串2/2 (看更多)
基本上很難知道收幾次可以收完,一般來說應該是不會要求到這個部分 就算這樣用: byte[] arr=new byte[1000]; input.read(arr,0,arr.length); 也不能保證每次都會收到 1000 個 byte 所以重點應該在收到資料要怎麼處理的部分吧 ! ObjectOutputStream out = new ObjectOutputStream(socket.getOutputStream()); ! String []hh = new String[6]; //demo 長度給少一點 hh[0]="String1"; hh[1]="String2"; hh[2]="String3"; hh[3]="String4"; hh[4]="String5"; hh[5]="String6"; - for(int i=0;i<=5;i++){ - String outData = hh[i]; - byte [] outByte = outData.getBytes(); - out.write(outByte , 0 , outByte.length); - out.flush(); - System.out.println(outData); - } + out.writeObject(hh); + out.close(); ! ObjectInputStream in = new ObjectInputStream(socket.getInputStream()); + String[] strArray=(String[])(in.readObject()); ! for(int i=0;i<=strArray.length;i++){ - byte[] inByte = new byte[1000]; - in.read(inByte); - String servermsg = new String(inByte , 0 , inByte.length); - System.out.println("Message from server : "+i); ! System.out.println(strArray[i]); } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 122.123.85.7

09/12 10:30, , 1F
非常感謝<(_ _)>
09/12 10:30, 1F

09/12 17:00, , 2F
頂問前面的! - + 是什麼意思?這是什麼用法啊?
09/12 17:00, 2F

09/12 17:04, , 3F
+:增加這行 -:移除這行 !:有修改過
09/12 17:04, 3F

09/12 17:06, , 4F
之前在改BBS原始碼的時候,給讀者看比較的標註方式而已XD
09/12 17:06, 4F

09/12 17:07, , 5F
diff ?
09/12 17:07, 5F

09/12 17:14, , 6F
瞭解了 感謝解說
09/12 17:14, 6F
文章代碼(AID): #1EREPvho (java)
文章代碼(AID): #1EREPvho (java)