组网方式

发布于 2024-08-14 17:04:25 字数 82 浏览 8 评论 0原文

嘿伙计们,我注意到,当我发送一个完整的数据包(将其数据收集到缓冲区中并发送)时,它比逐字节发送数据包要慢得多。 如果我用这种方法做一个网络游戏可以吗?

Hey guys, Iv'e noticed that when I send a complete packet (collect it's data in a buffer and send) it is much slower than sending the packet byte by byte.
Will it be okay if I make an online game using this method?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

玻璃人 2024-08-21 17:04:25

听起来像是一个与烦人相关的问题。

您必须禁用对延迟要求较高的应用程序的唠叨。 (参见setsockopt、TCP_NODELAY)。

说明:

TCP 堆栈对于小块的行为有所不同,尝试以奇怪的方式将它们组合成 IP 数据报。这是 J.Nagle 建议的性能优化(因此称为 nagling)。请记住,启用 NODELAY 将使每个 send() 调用都进行内核模式转换,因此如果性能是您的问题,您可能希望在将流送入 send() 之前,通过内存复制的方式将流打包成块。正在做。

Sounds like a naggling-related problem.

You have to disable naggling for latency-demanding applications. (See setsockopt, TCP_NODELAY).

Explanation:

TCP stack behaves differently for small chunks, trying to combine them in bizare ways on the way to IP datagrams. This is a performance optimization suggested by J.Nagle (hence nagling). Keep in mind that enabling NODELAY will make every send() call a kernel-mode transition, so you may wish to pack streams into chunks yourself by means of memory copying, before feeding them into send() if performance is an issue for what you are doing.

梦魇绽荼蘼 2024-08-21 17:04:25

我认为你需要定义你的测量点(你到底在测量什么)。请问这是TCP还是UDP?

无论如何,Winsock 有其自己的内部缓冲区,您可以通过调用

I think you need to define what are your measurement points (what exactly are you measuring). By the way is this TCP or UDP?

Anyway Winsock has its own internal buffers that you can modify by calls to setsockopt.

想挽留 2024-08-21 17:04:25

这听起来很奇怪。逐字节发送数据的开销要大得多。您的传输标头将远远超过有效负载!更不用说 O(n) send 调用(其中 n 是字节数)。

如果这就是你所经历的,那么你就做错了。

That sounds bizarre. There is much more overhead in sending data byte by byte. Your transport headers will far outweigh the payload! Not to mention O(n) send calls (where n is the number of bytes).

You're doing something wrong if that's what you experience.

春花秋月 2024-08-21 17:04:25

我没有真正测量任何东西,我很确定它与发送数据而不是收集数据有关。
我在服务器端使用 C#,在客户端使用 C++,在服务器端我用 BinaryWriter 和 BinaryReader 包装套接字,在客户端我只使用 send 和 receive
发送每个字节。

What I didn't really measure anything, I'm pretty sure it has something to do with sending data and not collecting it..
I'm using C# for server-side and C++ for client side, in the server side I wrapped the socket with a BinaryWriter and BinaryReader, and in the client I just used send and recv
to send every byte.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文