优化 服务端 客户端代码
This commit is contained in:
@ -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("客户端已经启动");
|
||||||
}
|
}
|
||||||
|
@ -4,5 +4,5 @@ public class Config {
|
|||||||
// 设置协议版本,1 表示 RIP v1,2 表示 RIP v2
|
// 设置协议版本,1 表示 RIP v1,2 表示 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;
|
||||||
}
|
}
|
||||||
|
@ -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()) {
|
||||||
// 更新本地路由表
|
// 更新本地路由表
|
||||||
|
Reference in New Issue
Block a user