一个按钮,点击调用shut_code发送信息。shut_code贴上:
private void shut_code()
{
String msg= "shutdown";
int port = 8099;
DatagramSocket s = null;
try{
s = new DatagramSocket();
}catch(SocketException e){
e.printStackTrace();
}
InetAddress local = null;
try{
local = InetAddress.getByName("192.168.1.211");
}catch(UnknownHostException e){
e.printStackTrace();
}
int msg_length = msg.length();
byte[] msgbyte = msg.getBytes();
DatagramPacket p = new DatagramPacket(msgbyte,msg_length,local,port);
try{
s.send(p);
}catch(IOException e){
e.printStackTrace();
}
}
在模拟器上运行正常,android版本设定的是4.0,真机也是4.0的
android模拟器运行正常,真机测试程序崩溃
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-