//聲明量
為正鑲白等地區(qū)用戶提供了全套網頁設計制作服務,及正鑲白網站建設行業(yè)解決方案。主營業(yè)務為成都網站設計、成都做網站、正鑲白網站設計,以傳統(tǒng)方式定制建設網站,并提供域名空間備案等一條龍服務,秉承以專業(yè)、用心的態(tài)度為用戶提供真誠的服務。我們深信只要達到每一位用戶的要求,就會得到認可,從而選擇與我們長期合作。這樣,我們也可以走得更遠!
private String IPaddress="192.168.1.120";
private int port =50003;
private Handler mhandler =null;
private String cc ="";
private TextView returnvalue;
// 動態(tài)接收數(shù)據(jù)
mhandler = new Handler(){
public voidhandleMessage(Message msg)
{
if(msg.what== 1)
{
if(cc!=null||cc!="")
{
returnvalue.setText(cc);
cc=null;
}
}
super.handleMessage(msg);
}
};
//啟動相關線程
serverThread thread = new serverThread();
thread.start();
//創(chuàng)建并發(fā)送數(shù)據(jù)
byte[] buf = {(byte)0x55,(byte)0xAA};
try {
socket = newSocket(this.IPaddress,this.port);
OutputStream out =socket.getOutputStream();
OutputStreamWriter writer =new OutputStreamWriter(out);
out.write(buf);
writer.flush();
Toast.makeText(PauseActivity.this,"成功",
Toast.LENGTH_SHORT).show();
} catch (UnknownHostExceptione) {
Toast.makeText(PauseActivity.this, "異常",
Toast.LENGTH_SHORT).show();
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
//接受數(shù)據(jù)
public class serverThread extendsThread {
publicvoid run() {
while(!Thread.currentThread().isInterrupted()){
if(socket==null)
{
try {
Thread.sleep(1000);
} catch(InterruptedException e) {
// TODOAuto-generated catch block
e.printStackTrace();
}
}else
{
try {
Thread.sleep(1000);
InputStreamips=socket.getInputStream();
InputStreamReader in = new InputStreamReader(ips);
in.ready();
cc ="";
for(inti= 0 ;i<2 ;i++)
{
cc+=ips.read()+"-";
}
} catch(InterruptedException e) {
e.printStackTrace();
} catch(IOException e) {
e.printStackTrace();
}
Message msg = newMessage();
msg.what= 1;
mhandler.sendMessage(msg);
}
}
}
}
//新人求關注