public String startDs() {
DatagramSocket socket = null;
try {
socket = new DatagramSocket(8800);
} catch (SocketException e) {
e.printStackTrace();
}
//记录客户端的数量
int count = 0;
while (true) {
data = new byte[16];// 创建字节数组,指定接收的数据包的大小
packet = new DatagramPacket(data, data.length);
try {
socket.receive(packet);
} catch (IOException e) {
e.printStackTrace();
} // 此方法在接收到数据报之前会一直阻塞
Thread thread = new Thread(new UDPThread(socket, packet));
thread.start();
}
}
这种一般是你运算数据太耗时了,优化下你的逻辑跟算法(优先优化逻辑)
对,这个还得从运算逻辑这个点来修改,这里太耗时。