TCP和Node.js的实时多人游戏原则

时间:2022-07-17 18:57:44

I've been reading the Valve article on multi-player networking which has been adapted from Yahn Bernier's 2001 paper called Latency Compensating Methods in Client/Server In-game Protocol Design and Optimization. I'm making a realtime multi-player game using a node.js server connected to clients through socket.io and I have a few questions regarding the principles detailed below:

我一直在阅读关于多玩家网络的Valve文章,该文章改编自Yahn Bernier 2001年的一篇名为“客户/服务器游戏内协议设计和优化中的延迟补偿方法”的论文。我正在使用通过socket.io连接到客户端的node.js服务器进行实时多人游戏,我对下面详述的原则有几个问题:

Entity Interpolation

实体插值

[Interpolation] prevents the jittery motion this would ordinarily lead to by buffering server updates then playing them back with the gaps smoothly interpolated between. It can also protect against glitches caused by packet loss.

[插值]通过缓冲服务器更新然后播放它们之间平滑插入的间隙来防止通常会导致的抖动。它还可以防止数据包丢失引起的故障。

Client-Side Prediction

客户端预测

Prediction is the notion of the client predicting the effects of the local player's actions without waiting for the server to confirm them. An entity's predicted state is tested against server commands as they arrive until either a match or a mis-match is detected.

预测是客户端在不等待服务器确认的情况下预测本地玩家行为的影响的概念。实体的预测状态在服务器命令到达时进行测试,直到检测到匹配或不匹配为止。

Lag Compensation

滞后补偿

Lag compensation is the notion of the server using a player's latency to rewind time when processing [user input], in order to see what the player saw when the command was sent. In combination with prediction, lag compensation can help to combat network latency to the point of almost eliminating it from the perspective of an attacker.

滞后补偿是服务器在处理[用户输入]时使用播放器延迟倒带时间的概念,以便查看播放器在发送命令时看到的内容。与预测相结合,滞后补偿可以帮助抵御网络延迟,从攻击者的角度来看几乎消除它。

  • Do the principles apply to TCP as they do to UDP and would there be any differences in implementation? I can see that the entity interpolation would not need to protect against packet loss but thats about it.

    这些原则是否适用于TCP,因为它们对UDP有效,是否会在实现方面有任何差异?我可以看到实体插值不需要防止数据包丢失,但就此而言。

  • Can I even communicate between a server and web-browser and vice-versa using UDP and Node.js?

    我甚至可以使用UDP和Node.js在服务器和Web浏览器之间进行通信,反之亦然?

  • Since the paper is over a decade old are these principles still in use or has other technology appeared?

    由于这篇论文已有十多年的历史,这些原则还在使用还是出现了其他技术?

Any help would be much appreciated.

任何帮助将非常感激。

1 个解决方案

#1


2  

  • Do the principles apply to TCP as they do to UDP and would there be any differences in implementation? I can see that the entity interpolation would not need to protect against packet loss but thats about it.
  • 这些原则是否适用于TCP,因为它们对UDP有效,是否会在实现方面有任何差异?我可以看到实体插值不需要防止数据包丢失,但就此而言。

Although you won't have to deal with packet loss, you will have to deal with longer transit times. TCP is slower than UDP and you'll have to mitigate that in realtime multiplayer. I would think that these principles still apply at a fundamental level.

虽然您不必处理数据包丢失,但您必须处理更长的传输时间。 TCP比UDP慢,你必须在实时多人游戏中缓解这一点。我认为这些原则仍然适用于基础层面。

  • Can I even communicate between a server and web-browser and vice-versa using UDP and Node.js?
  • 我甚至可以使用UDP和Node.js在服务器和Web浏览器之间进行通信,反之亦然?

Generally speaking, not yet. At least not without some form of browser extension or plugin - WebSockets use TCP. That said, WebRTC (and more specifically, the PeerConnection API) is coming. When data channels are implemented, UDP communications should, in theory, be possible.

一般来说,还没有。至少没有某种形式的浏览器扩展或插件 - WebSockets使用TCP。也就是说,WebRTC(更具体地说,PeerConnection API)即将推出。当实现数据信道时,理论上UDP通信应该是可能的。

  • Since the paper is over a decade old are these principles still in use or has other technology appeared?
  • 由于这篇论文已有十多年的历史,这些原则还在使用还是出现了其他技术?

I'd be very surprised to hear that they're no longer in use - the article you've cited is practically required reading for game programmers. Ditto for new techniques not appearing, though I haven't been paying close attention to developments in this area for several years now.

听到他们已经不再使用我会感到非常惊讶 - 你引用的文章实际上是游戏程序员必读的。同样没有出现新技术,但我几年来一直没有密切关注这方面的发展。

#1


2  

  • Do the principles apply to TCP as they do to UDP and would there be any differences in implementation? I can see that the entity interpolation would not need to protect against packet loss but thats about it.
  • 这些原则是否适用于TCP,因为它们对UDP有效,是否会在实现方面有任何差异?我可以看到实体插值不需要防止数据包丢失,但就此而言。

Although you won't have to deal with packet loss, you will have to deal with longer transit times. TCP is slower than UDP and you'll have to mitigate that in realtime multiplayer. I would think that these principles still apply at a fundamental level.

虽然您不必处理数据包丢失,但您必须处理更长的传输时间。 TCP比UDP慢,你必须在实时多人游戏中缓解这一点。我认为这些原则仍然适用于基础层面。

  • Can I even communicate between a server and web-browser and vice-versa using UDP and Node.js?
  • 我甚至可以使用UDP和Node.js在服务器和Web浏览器之间进行通信,反之亦然?

Generally speaking, not yet. At least not without some form of browser extension or plugin - WebSockets use TCP. That said, WebRTC (and more specifically, the PeerConnection API) is coming. When data channels are implemented, UDP communications should, in theory, be possible.

一般来说,还没有。至少没有某种形式的浏览器扩展或插件 - WebSockets使用TCP。也就是说,WebRTC(更具体地说,PeerConnection API)即将推出。当实现数据信道时,理论上UDP通信应该是可能的。

  • Since the paper is over a decade old are these principles still in use or has other technology appeared?
  • 由于这篇论文已有十多年的历史,这些原则还在使用还是出现了其他技术?

I'd be very surprised to hear that they're no longer in use - the article you've cited is practically required reading for game programmers. Ditto for new techniques not appearing, though I haven't been paying close attention to developments in this area for several years now.

听到他们已经不再使用我会感到非常惊讶 - 你引用的文章实际上是游戏程序员必读的。同样没有出现新技术,但我几年来一直没有密切关注这方面的发展。