傳輸資料的時間一直掛起處理不完執行緒是怎么回事?
uj5u.com熱心網友回復:
public static String sends(byte[] scr){Socket client=null;
InputStream in=null;
OutputStream out=null;
String msg=null;
boolean ming=false;
if(client==null){
try {
client=new Socket("192.168.7.1", 4622);
} catch (UnknownHostException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
} catch (IOException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
try {
client.setSoTimeout(3000);
in=client.getInputStream();
out=client.getOutputStream();
out.write(scr);
client.setSoTimeout(5*5000);
out.flush();
int count=0;
while(count==0){
count=in.available();
}
byte[] buffer=new byte[count];
in.read(buffer);
msg=bytes2HexString(buffer);
} catch (IOException e) {
// TODO Auto-generated catch block
try {
client.close();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
finally {
if (client != null) {
try {
client.close();
client.isConnected();
} catch (IOException e) {
// TODO Auto-generated catch block
client=null;
}
}
}
}
return msg;
}
只是貼的代碼
uj5u.com熱心網友回復:
我每次點擊一下按鈕都會呼叫一側這個類轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/131377.html
標籤:網絡通信
上一篇:0xAA怎么轉換為AA?
