网络游戏客户端如何能够如此快速地通过互联网交换数据?

发布于 2024-09-02 03:53:13 字数 344 浏览 7 评论 0原文

让我们想象一下非常简单的游戏...我们有一个迷宫和两个玩家试图通过互联网实时找到出口

在每次移动时,游戏客户端都应将玩家的坐标发送到服务器并接受另一个客户端的当前坐标。怎么可能让这种交换如此之快(就像所有现代游戏一样)。

好吧,我们可以使用memcache或者类似的技术来减少服务器端的数据挖掘操​​作。我们还可以使用最快的网络服务器等,但我们仍然会遇到计时问题。

那么,问题是...

  1. 游戏客户端通常使用什么协议与服务器交换信息?
  2. 哪些服务器技术可以解决这个问题?
  3. 应用什么算法来处理游戏等过程中出现延迟的战斗。

Let's imagine really simple game... We have a labirinth and two players trying to find out exit in real time through internet.

On every move game client should send player's coordinates to server and accept current coordinates of another client. How is it possible to make this exchange so fast (as all modern games do).

Ok, we can use memcache or similar technology to reduce data mining operations on server side. We can also use fastest webserver etc., but we still will have problems with timings.

So, the questions are...

  1. What protocol game clients are usually using for exchanging information with server?
  2. What server technologies are coming to solve this problem?
  3. What algorithms are applied for fighting with delays during game etc.

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

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

发布评论

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

评论(3

执着的年纪 2024-09-09 03:53:13

通常采用网络插值和预测。 Gamedev 是一个很好的资源:http://www.gamedev.net/reference/list .asp?categoryid=30

另请查看此:http://developer.valvesoftware.com /wiki/Source_Multiplayer_Networking

Usually with Network Interpolation and prediction. Gamedev is a good resource: http://www.gamedev.net/reference/list.asp?categoryid=30

Also check out this one: http://developer.valvesoftware.com/wiki/Source_Multiplayer_Networking

如若梦似彩虹 2024-09-09 03:53:13
  • 使用 UDP,而不是 TCP
  • 使用自定义协议,通常是定义“命令”的单个字节,并且包含命令参数预测的后续字节尽可能少,
  • 用于使其他玩家的动作显得平滑,而无需获取更新每个单帧

提示:无论如何,都会使用预测来平滑快速屏幕更新(~60fps),因为实际游戏速度通常较慢(~25fps)。

  • use UDP, not TCP
  • use a custom protocol, usually a single byte defining a "command", and as few subsequent bytes as possible containing the command arguments
  • prediction is used to make the other players' movements appear smooth without having to get an update for every single frame

hint: prediction is used anyway to smooth the fast screen update (~60fps) since the actual game speed is usually slower (~25fps).

飘逸的'云 2024-09-09 03:53:13

其他答案没有阐明原始帖子中的一些重要误解,即这些游戏不是网站并且运作方式完全不同。特别是:

  • 不需要或很少需要“数据挖掘”
    需要加快速度。最快在线
    游戏(例如第一人称射击游戏)
    通常不会保存任何内容
    比赛期间的磁盘。上网速度较慢
    游戏,例如 MMO,可能会使用
    数据库,主要用于存储
    玩家信息,但对于大多数
    他们将玩家和世界数据保存在内存中,
    不在磁盘上。
  • 他们不使用
    网络服务器。 HTTP 相对较慢
    协议,甚至 TCP 本身也可以
    对于某些游戏来说太慢了。相反,他们
    有专门为该特定游戏编写的定制服务器。通常,这些服务器会针对低延迟而不是吞吐量进行调整,因为它们通常不会像 Web 服务器那样提供大文档,而是提供许多微小的消息(例如,以字节而不是千字节为单位)。

解决了这两个问题后,您的速度问题就基本上消失了。您可以向服务器发送消息并在 100 毫秒内获得回复,并且每秒可以执行多次。

The other answers haven't spelled out a couple of important misconceptions in the original post, which is that these games aren't websites and operate quite differently. In particular:

  • There is no or little "data-mining" that needs
    to be speeded up. The fastest online
    games (eg. first person shooters)
    typically are not saving anything to
    disk during a match. Slower online
    games, such as MMOs, may use a
    database, primarily for storing
    player information, but for the most
    part they hold their player and world data in memory,
    not on disk.
  • They don't use
    webservers. HTTP is a relatively slow
    protocol, and even TCP alone can be
    too slow for some games. Instead they
    have bespoke servers that are written just for that particular game. Often these servers are tuned for low latency rather than throughput, because they typically don't serve up big documents like a web server would, but many tiny messages (eg. measured in bytes rather than kilobytes).

With those two issues covered, your speed problem largely goes away. You can send a message to a server and get a reply in under 100ms and can do that several times per second.

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