更改发送报文时 绑定的端口

This commit is contained in:
2024-12-01 16:40:19 +08:00
parent f379b02e61
commit 6203c43ebe
2 changed files with 9 additions and 11 deletions

View File

@ -18,14 +18,14 @@ public class RIPService {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
// 启动服务器 // 启动服务器
RIPServer server = new RIPServer(); // RIPServer server = new RIPServer();
new Thread(() -> { // new Thread(() -> {
try { // try {
server.start(); // server.start();
} catch (InterruptedException e) { // } catch (InterruptedException e) {
e.printStackTrace(); // e.printStackTrace();
} // }
}).start(); // }).start();
// 启动客户端 // 启动客户端
RIPClient client = new RIPClient(); RIPClient client = new RIPClient();

View File

@ -36,14 +36,12 @@ public class RIPClient {
public void sendRipPacket(RIPPacket packet) { public void sendRipPacket(RIPPacket packet) {
try { try {
ChannelFuture future = bootstrap.bind(InetAddress.getByName("192.168.123.45"), 520) ChannelFuture future = bootstrap.bind(0)
.sync(); .sync();
future.channel().writeAndFlush(packet).sync(); future.channel().writeAndFlush(packet).sync();
future.channel().close(); future.channel().close();
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); e.printStackTrace();
} catch (UnknownHostException e) {
throw new RuntimeException(e);
} }
} }