java tcp socket通信协议_基于TCP协议的socket传输,java实现

外国教授的要求我不太清楚,是不是这个意思,文本文档里存储了主机和端口号,从文本文档随机读取一行目的主机和端口,然后建立连接,发送5个随机整数(+或-),之后关闭连接,10个进程...

外国教授的要求我不太清楚,是不是这个意思,文本文档里存储了主机和端口号,从文本文档随机读取一行目的主机和端口,然后建立连接,发送5个随机整数(+或-),之后关闭连接,10个进程,每个进程都重复这样的步骤5000次。

我的问题是,随机读取端口号建立链接这步怎么实现,网上的教学都是指定好了固定的IP和端口(例如Socket s = new Socket("100.65.27.22", 10005);)。

PS JAVA初学,以前只学过C和C++

原文:

In this assignment, you will be creating a set of processes P that are launched on different machines. At each process, you will read information about this set of processes from a text file: each line in the file will contain the host and port information for the process comprising this set. A process should never attempt to connect to itself; so it should not appear its list of available processes. It follows that the config file at each process will be different.

Each process participates in a set of rounds. Each round involves a process connecting to a randomly chosen process in the set of processes P. All communications in the system will be based on TCP. Once a connection is established to a random node, the initiating process sends 5 messages to the targeted process. The payload of each message is a random integer (positive or negative). At the end of each round the socket connection is closed and the process is repeated by choosing another node at random from the set P. Each process will initiate 5000 such rounds.

译文:

在此作业中,您将创建一组在不同机器上启动的进程P。在每个进程中,您将从文本文件中读取有关此组进程的信息:文件中的每一行将包含包含此集合的进程的主机和端口信息。进程不应该尝试连接到自己;所以它不应该出现其可用进程的列表。因此,每个进程的配置文件将不同。

每个进程都参与几轮。每一轮涉及到一组进程连接到随机选择的进程。系统中的所有通信将基于TCP。一旦连接建立到随机节点,启动过程就会向目标进程发送5条消息。每个消息的有效负载是一个随机整数(正或负)。在每一轮结束时,套接字连接被关闭,并且通过从集合P中随机选择另一个节点来重复该过程。每个过程将发起5000个这样的回合。

展开

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值