androidDatagramSocketsend发送数据出错-创新互联
以下代码是我点击发送是代码:
创新互联是一家专业提供达州企业网站建设,专注与成都网站设计、网站制作、H5页面制作、小程序制作等业务。10年已为达州众多企业、政府机构等服务。创新互联专业的建站公司优惠进行中。new Thread(new Runnable() {
@Override
public void run() {
try {
sendData();
} catch (Exception e) {
Log.e(_TAG, "Check: Error2: " + e);
} finally {
}
}
}).start();
private void sendData()
{
DatagramSocket socket=null;
try {
socket = new DatagramSocket();
} catch (SocketException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
InetAddress serverAddress=null;
try {
serverAddress = InetAddress.getByName("192.168.1.101");
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String str = "hello";
byte data[] = str.getBytes();
DatagramPacket pkdata = new DatagramPacket (data , data.length , serverAddress , 8899);
try {
socket.send(pkdata);
} catch (IOException e) {
// TODO Auto-generated catch block
Log.v(null,e.getMessage()+"11111111111");
e.printStackTrace();
}
finally {
if (null != socket) {
socket.close();
socket = null;
}
}
}
文章题目:androidDatagramSocketsend发送数据出错-创新互联
文章起源:http://azwzsj.com/article/dojoee.html