这是我的代码,我不知道为什么UDP_packet.send(outgoing);抛出异常
int SERVERPORT = 9876;
InetAddress SERVER_IP = InetAddress.getByName("127.0.0.1");
// send UDP packet
DatagramSocket UDP_packet = new DatagramSocket(SERVERPORT);
UDP_packet.setBroadcast(true);
String fxx = latcrd.getText().toString();
String fyy = longcrd.getText().toString();
String str = fxx + "," + fyy;
byte[] b = str.getBytes();
DatagramPacket outgoing = new DatagramPacket(b, b.length,
SERVER_IP, SERVERPORT);
try{
UDP_packet.send(outgoing);
}
catch(Exception e)
{
e.printStackTrace();
}
之前它是正常的,但现在它停止工作,我真的不知道是什么问题
好了,我得到了我自己问题的答案。实际上,我在主线程网络上发送一个udp数据包,它是不允许在主线程网络上发送数据包的。由于