mirror of
https://github.com/moparisthebest/Conversations
synced 2024-11-28 19:52:15 -05:00
Close DatagramSocket using try-with-resources
This commit is contained in:
parent
3236432c39
commit
defe519101
@ -131,18 +131,19 @@ public class Client {
|
|||||||
message.setRecursionDesired(true);
|
message.setRecursionDesired(true);
|
||||||
message.setId(random.nextInt());
|
message.setId(random.nextInt());
|
||||||
byte[] buf = message.toArray();
|
byte[] buf = message.toArray();
|
||||||
DatagramSocket socket = new DatagramSocket();
|
try (DatagramSocket socket = new DatagramSocket()) {
|
||||||
DatagramPacket packet = new DatagramPacket(
|
DatagramPacket packet = new DatagramPacket(buf, buf.length,
|
||||||
buf, buf.length, InetAddress.getByName(host), port);
|
InetAddress.getByName(host), port);
|
||||||
socket.setSoTimeout(timeout);
|
socket.setSoTimeout(timeout);
|
||||||
socket.send(packet);
|
socket.send(packet);
|
||||||
packet = new DatagramPacket(new byte[bufferSize], bufferSize);
|
packet = new DatagramPacket(new byte[bufferSize], bufferSize);
|
||||||
socket.receive(packet);
|
socket.receive(packet);
|
||||||
DNSMessage dnsMessage = DNSMessage.parse(packet.getData());
|
DNSMessage dnsMessage = DNSMessage.parse(packet.getData());
|
||||||
if (dnsMessage.getId() != message.getId()) {
|
if (dnsMessage.getId() != message.getId()) {
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
|
return dnsMessage;
|
||||||
}
|
}
|
||||||
return dnsMessage;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user