优化 服务端 客户端代码

This commit is contained in:
2024-12-01 17:59:34 +08:00
parent a9afea0603
commit 638507e0f3
3 changed files with 3 additions and 1 deletions

View File

@ -38,6 +38,7 @@ public class RIPService {
scheduler.scheduleAtFixedRate(() -> { scheduler.scheduleAtFixedRate(() -> {
RIPPacket packet = createRipResponsePacket(Config.RIP_VERSION); RIPPacket packet = createRipResponsePacket(Config.RIP_VERSION);
client.sendRipPacket(packet); client.sendRipPacket(packet);
System.out.println("客户端 发送了一次消息");
}, 0, 10, TimeUnit.SECONDS); }, 0, 10, TimeUnit.SECONDS);
System.out.println("客户端已经启动"); System.out.println("客户端已经启动");
} }

View File

@ -4,5 +4,5 @@ public class Config {
// 设置协议版本1 表示 RIP v12 表示 RIP v2 // 设置协议版本1 表示 RIP v12 表示 RIP v2
public static final byte RIP_VERSION = 2; public static final byte RIP_VERSION = 2;
public static final boolean startServer = true; public static final boolean startServer = true;
public static final boolean startClient = true; public static final boolean startClient = false;
} }

View File

@ -11,6 +11,7 @@ public class RIPServerHandler extends SimpleChannelInboundHandler<RIPPacket> {
@Override @Override
protected void channelRead0(ChannelHandlerContext ctx, RIPPacket msg) throws Exception { protected void channelRead0(ChannelHandlerContext ctx, RIPPacket msg) throws Exception {
System.out.println(msg);
if (msg.getCommand() == 2) { // Response if (msg.getCommand() == 2) { // Response
for (RIPEntry entry : msg.getEntries()) { for (RIPEntry entry : msg.getEntries()) {
// 更新本地路由表 // 更新本地路由表