Java套接字-如何模拟多个客户端 [英] Java sockets - How to simulate multiple clients

查看:149
本文介绍了Java套接字-如何模拟多个客户端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用Java编写的套接字程序。

I have a socket program written in Java.

服务器利用DatagramSocket创建具有特定端口号的套接字。我有一个客户端Java程序,该程序连接到该服务器并发送一些消息。

The server makes use of DatagramSocket to create a socket with a particular port number. I have a client java program, which connects to this server and sends some messages.

当前我有3台笔记本电脑,所以我用1台笔记本电脑运行服务器,其余2台笔记本电脑运行成为客户。如何模拟100个客户端?

Currently I have 3 laptops so I use 1 to run the server and the remaining 2 to be clients. How can I simulate 100 clients?

我正在考虑为客户端编写一个包装器,并对其进行100次调用,但是问题出在那些模拟客户端的IP地址上,是唯一的。任何指导表示赞赏。

I am thinking of writing a wrapper around the clients and call them 100 times, but the problem is with the ip-address for those simulated clients NOT being unique. Any guidance appreciated.

推荐答案


问题在于那些模拟客户端的IP地址不唯一

the problem is with the ip-address for those simulated clients NOT being unique

不,问题在于您只能通过其IP地址识别客户端。您应该使用IP:port,例如,通过 DatagramSocket.getRemoteSocketAddress()。

No, the problem is that you are only identifying clients by their IP address. You should use IP:port, for example, via DatagramSocket.getRemoteSocketAddress().

然后可以通过在单个主机上运行100个客户端程序实例。

Then you can test by running 100 instances of your client program in a single host.

这篇关于Java套接字-如何模拟多个客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆