看板 java 關於我們 聯絡資訊
基本上很難知道收幾次可以收完,一般來說應該是不會要求到這個部分 就算這樣用: 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
wheredo:非常感謝<(_ _)> 09/12 10:30
LaPass:頂問前面的! - + 是什麼意思?這是什麼用法啊? 09/12 17:00
darkk6:+:增加這行 -:移除這行 !:有修改過 09/12 17:04
darkk6:之前在改BBS原始碼的時候,給讀者看比較的標註方式而已XD 09/12 17:06
laiis:diff ? 09/12 17:07
LaPass:瞭解了 感謝解說 09/12 17:14