当前仓库属于关闭状态,部分功能使用受限,详情请查阅 仓库状态说明
3 Star 2 Fork 1

cyijun/dns-server-java
关闭

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
ResponseHandleThread.java 1.95 KB
一键复制 编辑 原始数据 按行查看 历史
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();
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/yijunc/dns-server-java.git
git@gitee.com:yijunc/dns-server-java.git
yijunc
dns-server-java
dns-server-java
master

搜索帮助