代码拉取完成,页面将自动刷新
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.net.UnknownHostException;
import java.util.HashMap;
class ResponseHandleThread extends Thread {
private DatagramPacket packet;
private DatagramSocket socket;
public ResponseHandleThread(DatagramPacket packet, DatagramSocket socket) {
this.packet = packet;
this.socket = socket;
}
@Override
public synchronized void run() {
byte[] payload = packet.getData();
try {
// while(!flag){}
// flag = false;
HashMap<String, String> rMap = Server.bytes2Map(payload);
String tId = rMap.get("ID");
for (HashMap<String, String> map : Server.mapList) {
if (map.get("ID").equals(tId)) {
String host = map.get("CLIADDR").replaceAll("/", "").split(":")[0];
Integer port = Integer.parseInt(map.get("CLIADDR").replaceAll("/", "").split(":")[1]);
SocketAddress clientAddr = new InetSocketAddress(host, port);
DatagramPacket rPacket = new DatagramPacket(payload, payload.length, clientAddr);
if(Server.dbgLvFlag==1){
System.out.println("获得外部返回数据后,将其转发,域名为:"+map.get("QNAME")+"类型为"+map.get("QTYPE"));
}
socket.send(rPacket);
if(Server.dbgLvFlag>=2)
System.out.println("Send to " + host + ":" + port + " -- " + rMap);
Server.mapList.remove(map);
}
}
// flag = true;
} catch (UnsupportedEncodingException | UnknownHostException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。