java套接字多客户端,Java套接字 - 如何模拟多个客户端(Java sockets - How to simulate multiple clients)...

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

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

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

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

我正在考虑在客户端周围编写一个包装器并调用它们100次,但问题在于那些模拟客户端的ip-address 不是唯一的。 任何指导赞赏。

I have a socket program written in 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.

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?

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.

原文:https://stackoverflow.com/questions/29725339

2020-02-22 14:26

满意答案

问题在于那些模拟客户端的ip-address不是唯一的

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

然后,您可以通过在单个主机中运行100个客户端程序实例来进行测试。

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

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

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

2015-04-19

相关问答

您必须为每个客户端启动一个新线程,因为套接字需要一个线程来运行(因为它大部分时间都在等待输入)。 这可以例如完成(以这种简化的方式): public class ThreadHandler extends Thread {

private ArrayList serverThreads = new ArrayList();

public void run() {

while (!isInterr...

你的想法是对的。 一个小的评论是客户端端口可以由系统自动分配。 Your idea is correct. One minor comment is that the client ports can be automatically allocated by system.

UDP多播系统可以为此工作,但您自己也会变得复杂(因为您必须担心自己的同步和故障检测/纠正以及节点进出组)。 有各种中间件解决方案,包括分布式缓存,已经很好地解决了这个问题。 看看Infinispan。 如果这个级别太高而您只想要一个较低级别的解决方案,请尝试使用JGroups。 我只列出那些因为我知道它们快速可用,但还有很多其他的。 A UDP multicast system would work for this but will get complicated for you to do ...

您可以使用 我认为ServerSocketChannel是这样做的,尽管我还没有尝试过这样做。 您可以查看此stackoverflow线程以获取更多信息。 Java Server - 多个端口 You can use ServerSocketChannel to do that I think, though I have not yet tried to do the same. You can see this stackoverflow thread for more information...

啊,愚蠢的错误! 我丢失了对客户端套接字的引用,因此在尝试关闭它时,抛出异常,但被抑制了......只需关闭套接字即可关闭客户端的telnet会话。 Ah, stupid mistake! I lost the reference to the client's socket and thus when trying to close it, an exception was thrown, but was suppressed... Simply closing the socket close...

忘了我第一次编辑代码...基本上服务器的try语句是在while循环中允许多个连接。 在此浪费了2个小时; 伤心... Forgot that I edited the code the first time... Basically the try statement of the server was in a while loop to allow multiple connections. Wasted a good 2 hours on this; sad...

您应该在不同的客户端之间共享ClientSocketChannelFactory。 其余部分应与示例中的相同。 如果你不共享,你将创建太多的线程。 You should share the ClientSocketChannelFactory between your different clients. The rest should be the same as in the example. If you not share you will create too many threads....

因此,由于还没有人回答,我做了一些挖掘并绕过它。 但它包括一个循环。 所以有几米。 我可以使用套接字写入和循环将数据发送到仪表。 没有使上述代码工作的部分是在发送100米的请求数据包时,它实际上接收前8个字节并拒绝其余的。 所以我添加了一个延迟睡眠(1),代码就像魅力一样 So since no one yet answered, I did some digging and got a way around it. But it includes a loop. So there was a c...

问题在于那些模拟客户端的ip-address不是唯一的 不,问题是您只是通过IP地址识别客户端。 您应该使用IP:port,例如,通过DatagramSocket.getRemoteSocketAddress(). 然后,您可以通过在单个主机中运行100个客户端程序实例来进行测试。 the problem is with the ip-address for those simulated clients NOT being unique No, the problem is that you a...

是的,您可以在Windows机器上轻松创建> 30,000个插槽,但您可能需要调整MAXUSERPORT (请参见此处 )。 使用I / O完成端口或异步I / O,然后您不必担心“轮询”和可扩展性“正常”。 主要的资源问题是非页面缓冲池,但这在Vista或更高版本(见此处 )上已成为一个问题,下一个问题是I / O锁定页面限制,如果您发布非常大的缓冲区可能会出现问题对于你的读取,但鉴于这是UDP我假设你将有'合理'大小的数据报,因此锁定的页面限制不太可能是一个问题。 我在这里写了一些关于可伸缩性...

相关文章

引入kafka-clients相关依赖 <dependency> <group

...

1. 背景 多核,官方说法,让你只用一个Solr实例,实现多配置多索引的功能,为不同的应用保留不同的

...

微信开发本地调试工具(模拟微信客户端) 微信部署需要依靠80端口,如何快速有效的调试本地微信开发程 序

...

简介 SolrJ是操作Solr的JAVA客户端,它提供了增加、修改、删除、查询Solr索引的JAV

...

solr的服务器端配置晚上有很多文章。 solr的客户端可以采用JAVA,PYTHON,C#,PHP,

...

有没有整过webService的, 客户端java.lang.IllegalStateExcepti

...

之前有和大家分享过关于"分享新浪微博"的博客,实现分享到微信在网上找了这方面的资料

...

我在写一程序,客户端用HTTP向服务器请求文件,服务器返回文件数据 OutputStream out

...

在Hadoop中为了方便集群中各个组件之间的通信,它采用了RPC,当然为了提高组件之间的通信效率以及考

...

最新问答

如果启用了复制处理程序,请确保将其置于其中一个安全角色之后。 我见过人们做的另一件事是在不同的端口上运行admin。 最好在需要auth的页面上使用SSL,这样你就不会发送明确的密码,因此管理和复制将发生在8443上,而常规查询将在8080上发生。 如果您要签署自己的证书,请查看此有用的SO页面: 如何在特定连接上使用不同的证书? I didn't know that /admin was the context for SOLR admin because /admin does not re

第一:在您的样本中,您有: 但是你在询问 //td[@class=‘CarMiniProfile-TableHeader’] (注意TableHeader中的大写'T')。 xpath区分大小写。 第二:通过查询// td [@ class ='CarMiniProfile-TableHeader'] / td,你暗示你在外部td中有一个'td'元素,而它们是兄弟姐妹。 有很多方法可以在这里获得制作和模型

这是你的答案: http://jsfiddle.net/gPsdk/40/ .preloader-container { position: absolute; top: 0px; right: 0px; bottom: 0px; left: 0px; background: #FFFFFF; z-index: 5; opacity: 1; -webkit-transition: all 500ms ease-out;

问题是,在启用Outlook库引用的情况下, olMailItem是一个保留常量,我认为当您将Dim olMailItem as Outlook.MailItem ,这不是问题,但是尝试设置变量会导致问题。 以下是完整的解释: 您已将olMailItem声明为对象变量。 在赋值语句的右侧,在将其值设置为对象的实例之前,您将引用此Object 。 这基本上是一个递归错误,因为你有对象试图自己分配自己。 还有另一个潜在的错误,如果之前已经分配了olMailItem ,这个语句会引发另一个错误(可能是

我建议使用wireshark http://www.wireshark.org/通过记录(“捕获”)设备可以看到的网络流量副本来“监听”网络上发生的对话。 当您开始捕获时,数据量似乎过大,但如果您能够发现任何看起来像您的SOAP消息的片段(应该很容易发现),那么您可以通过右键单击并选择来快速过滤到该对话'关注TCP Stream'。 然后,您可以在弹出窗口中查看您编写的SOAP服务与Silverlight客户端之间的整个对话。 如果一切正常,请关闭弹出窗口。 作为一个额外的好处,wireshar

Android默认情况下不提供TextView的合理结果。 您可以使用以下库并实现适当的aligntment。 https://github.com/navabi/JustifiedTextView Android Does not provide Justified aligntment of TextView By default. You can use following library and achieve proper aligntment. https://github.com/

你的代码适合我: class apples { public static void main(String args[]) { System.out.println("Hello World!"); } } 我将它下载到c:\ temp \ apples.java。 以下是我编译和运行的方式: C:\temp>javac -cp . apples.java C:\temp>dir apples Volume in drive C is HP_PAV

12个十六进制数字(带前导0x)表示48位。 那是256 TB的虚拟地址空间。 在AMD64上阅读wiki(我假设你在上面,对吗?)架构http://en.wikipedia.org/wiki/X86-64 12 hex digits (with leading 0x) mean 48 bits. That is 256 TB of virtual address space. Read wiki on AMD64 (I assume that you are on it, right?) ar

这将取决于你想要的。 对象有两种属性:类属性和实例属性。 类属性 类属性对于类的每个实例都是相同的对象。 class MyClass: class_attribute = [] 这里已经为类定义了MyClass.class_attribute ,您可以使用它。 如果您创建MyClass实例,则每个实例都可以访问相同的class_attribute 。 实例属性 instance属性仅在创建实例时可用,并且对于类的每个实例都是唯一的。 您只能在实例上使用它们。 在方法__init__中定

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值