java 模拟路由表_CommandThread.java

/* File: CommandThread.java

*

* Author: Venkata Sastry Malladi

*

* This file contains the code for the class CommandThread,

* which represents the thread spawned by each Router to

* listen for commands sent by the Command

*

* Preferred Editor: emacs

*/

import java.io.*;

import java.net.*;

class CommandThread extends Thread {

// the instance of the router that spawned this thread

Router r;

// the port on which the thread listens for commands from the Command

// program

int port;

/*

* Constructor

*

* @r: the instance of the router that spawned this thread @port: port

* number

*/

public CommandThread(Router r, int port,String threadName) {

// create the thread

super(threadName);

this.r = r;

this.port = port;

// start the thread;

start();

}

/*

* Method Name: run

*

* Use: To start the execution of the thread

*/

public void run() {

// socket to listen on the command port

ServerSocket l = null;

// socket to represent the accepted connection

Socket t;

// the input and output streams associated with the connection

ObjectOutputStream oos;

ObjectInputStream ois;

try {

// listen on the command port

l = new ServerSocket(port);

System.out.println("Router "+Thread.currentThread().getName()+" Command: Listening for commands on port "

+ port);

} catch (Exception e) {

System.out

.println("Router "+Thread.currentThread().getName()+" Command: Unable to open a listening socket on port: "

+ port);

System.out.println("Quitting.");

System.exit(1);

}

while (true) {

try {

// accept a connection

t = l.accept();

} catch (Exception e) {

System.out

.println("Router "+Thread.currentThread().getName()+" Command: An I/O error occured while accepting a connection");

continue;

}

try {

// open the streams

oos = new ObjectOutputStream(t.getOutputStream());

ois = new ObjectInputStream(t.getInputStream());

// read the command

String in = (String) ois.readObject();

// execute the command and send the response

String out = r.executeCommand(in);

oos.writeObject(out);

// close the streams and the connection

ois.close();

oos.close();

t.close();

} catch (Exception e) {

System.out

.println("Router "+Thread.currentThread().getName()+" Command: An I/O error occured while communicating with COMMAND");

continue;

}

}

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: net-tools-2.0-0.24.20131004git.el7.x86_64.rpm是一个用于Linux操作系统的网络工具软件包。该软件包包含了许多常用的网络工具,用于网络配置和网络连接的管理。 该软件包中的一些常见工具包括ifconfig、arp、route等。ifconfig用于配置网络接口,包括设置IP地址、子网掩码、网关等。arp用于查看和修改ARP缓存表,用于解析IP地址和MAC地址的映射关系。route工具用于配置和查看系统的路由表。 此外,软件包中还包含了一些其他功能的工具,如netstat用于显示网络连接、监听端口和网络统计信息;dnsdomainname用于查看和设置系统的DNS域名;hostname用于查看和设置系统的主机名等。 该软件包提供了一套方便实用的命令行工具,用于网络配置和网络故障排查。它们可以帮助系统管理员进行网络设置、网络故障排查等任务,提高了系统管理的效率和便利性。 总之,net-tools-2.0-0.24.20131004git.el7.x86_64.rpm是一个功能强大的网络工具软件包,提供了丰富实用的命令行工具,对于Linux系统的网络配置和管理非常有用。 ### 回答2: net-tools-2.0-0.24.20131004git.el7.x86_64.rpm是一个用于网络配置和诊断的软件包。它为Linux操作系统提供了一些命令行工具,使用户能够管理网络设置和进行网络故障排除。 该软件包提供的常用工具包括: 1. ifconfig:用于配置和显示当前网络接口的信息,如IP地址、子网掩码和MAC地址等。 2. netstat:用于显示网络连接的状态、路由表和接口统计数据等。 3. arp:用于显示和管理系统ARP(地址解析协议)缓存表。 4. route:用于配置和显示系统的路由表。 5. iptunnel:用于配置和管理IP隧道,以实现不同网络之间的连接。 6. nameif:用于将网络接口名字与MAC地址进行关联。 7. mii-tool:用于配置和显示网络接口的媒体独立接口属性。 通过使用net-tools软件包提供的这些工具,系统管理员可以轻松管理网络接口、配置路由表和跟踪网络连接等。这个软件包通常用于服务器和一些基于命令行的Linux发行版中。 ### 回答3: net-tools-2.0-0.24.20131004git.el7.x86_64.rpm 是一个用于Linux系统的网络工具包。该工具包提供了一系列用于管理和监控网络连接的命令和工具。 net-tools-2.0-0.24.20131004git.el7.x86_64.rpm 是一个RPM软件包文件,针对x86_64架构的CentOS 7操作系统。要安装该软件包,您可以使用以下命令: ``` sudo yum install net-tools-2.0-0.24.20131004git.el7.x86_64.rpm ``` 一旦安装完成,您将能够使用一些常用的网络工具来管理和监控网络连接。其中一些常见的命令包括: 1. ifconfig: 用于配置和显示网络接口信息,包括IP地址、网关、子网掩码等。 2. netstat: 用于显示网络连接状态和统计信息,包括当前连接的IP地址、端口号、状态等。 3. route: 用于显示和管理系统的路由表,包括路由规则、默认网关等。 4. arp: 用于显示和管理系统的ARP缓存表,包括IP地址和MAC地址的对应关系。 5. hostname: 用于显示或设置系统的主机名。 6. dnsdomainname: 用于显示或设置系统的DNS域名。 这些工具可以帮助您诊断和排除网络问题,并提供一个全面的网络连接状态概览。 总之,net-tools-2.0-0.24.20131004git.el7.x86_64.rpm 是一个用于Linux系统的网络工具包,提供了一系列用于管理和监控网络连接的命令和工具。您可以通过安装该RPM软件包来获取这些功能,并使用这些工具来配置、显示和管理网络接口、连接状态和路由等信息。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值