English 中文(简体)
我如何控制 Java(Jpcap)的交通速度。
原标题:How can I control the traffic speed (bytes sent) in Java (Jpcap)

我把网络模拟应用引入我的班子。 我已经做了整部法典,但我对控制所运送的交通速度感到不安。

用户可以输入他希望产生的预期速度(例如10个MiB/s)。 我以某种真正令人不安的方式来进行这种控制。 我在 Java发表了一份载有具体特质的UDP/TCP一揽子计划(例如8192tes)。 我知道这张画像是第二版,如果它已经达到极限(二秒或大小),则继续检查,直到它到达为止。 下面的算法解释了我的想法。

sendWithLimit (byte limit, JpcapSender sender, Packet pkg) {
     byte current = 0;
     long timeStamp = System.currentTimeMillis();

     while ((current < limit) && (System.currentTimeMillis() - timeStamp < 1000))
          sender.send(pkg);
          current += 8192;
     }
}

I think:这一办法相当贫穷,是否有更好的办法加以控制?

最佳回答

• 了解你在可达到的带宽内可以寄出的8192个包裹。 穿过许多包装(N),每只睡1 000/毫秒。 你们不得不对其进行微调,以说明实际上花了多少时间去派遣,但你们会得到一般的想法。

问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签