Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在为大学做一个项目。我正在做的应用程序是 Java 中的 UDP 和 TCP 客户端/服务器,我们必须测量发送一些数据所需的时间。我的问题是以下问题:
为了使应用程序更快,我想知道是否有任何方法可以在缓冲区中发送随机数据,我的意思是,我不想在我的计算机中使用我的文件之一,我只想发送例如 500 字节数据,但我不介意什么。我知道您可以直接从 Linux 终端或使用 Iperf 执行此操作,但我不知道如何在我的 Java 应用程序中实现它。
我将回答第一个问题,不知道 MTU 和 MSS。
要创建随机数据并发送它,您只需使用以下命令:
Random random = new Random(); byte[] data = new byte[500]; random.nextBytes(data); // fill with data try (OutputStream out = ...) { out.write(data); }