refactoring

pull/1461/merge
mrniko 4 weeks ago
parent bb0d14b44f
commit 7a733b8c81

@ -9,15 +9,20 @@ import io.netty.handler.codec.dns.*;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.util.concurrent.ThreadLocalRandom;
public class SimpleDnsServer { public class SimpleDnsServer {
private final EventLoopGroup group = new NioEventLoopGroup(); private final EventLoopGroup group = new NioEventLoopGroup();
private final Channel channel; private final Channel channel;
private String ip = "127.0.0.1"; private String ip = "127.0.0.1";
private final int port = 55; private final int port;
public SimpleDnsServer() throws InterruptedException { public SimpleDnsServer() throws InterruptedException {
this(ThreadLocalRandom.current().nextInt(50, 1000));
}
public SimpleDnsServer(int port) throws InterruptedException {
Bootstrap bootstrap = new Bootstrap(); Bootstrap bootstrap = new Bootstrap();
bootstrap.group(group) bootstrap.group(group)
.channel(NioDatagramChannel.class) .channel(NioDatagramChannel.class)
@ -30,6 +35,7 @@ public class SimpleDnsServer {
} }
}); });
this.port = port;
ChannelFuture future = bootstrap.bind(port).sync(); ChannelFuture future = bootstrap.bind(port).sync();
channel = future.channel(); channel = future.channel();
} }

Loading…
Cancel
Save