本文介绍了浏览器html5实时游戏。广播游戏状态选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为Facebook做实时游戏。现在我使用websockets广播状态。但是对于实时数据udp要好得多。我发现那里有WebRTC。但我不能使用它,因为它是对等的,我想要权威的服务器(运行物理,使之更难以作弊)。



我认为以下选项:


  1. 使用闪存套接字。但我从来没有使用闪光灯。甚至有可能在JavaScript中使用flash udp封装?它有多难?它是否需要一些特殊的东西在服务器端?
  2. 也许浏览器支持udp在某种方式?我可以使用udp将视频或音频流式传输到浏览器吗?也许有可能为我的游戏状态使用视频流

  3. 使用websockets。我有一些客户端的预测,我希望延迟时间会低于100毫秒(甚至更低,坦率地说,你可以) - 所以也许没关系?$ / b
  4. 使用这个WebRTC的东西。也许我可以以某种方式模拟服务器上的浏览器,并将其用作同行?例如,运行一堆chromes并通过websocket(无延迟,它们在一台机器上)将游戏数据发送给它们,然后通过udp流式传输到客户端?但浏览器可以限制点对点的连接,我需要在服务器上运行物理CPU

什么是最好的选择?你已经实现了其中的一个,结果是什么?

解决方案

你可以肯定地建立或使用服务器端组件支持WebRTC数据通道;从浏览器/客户端的角度来看,它只是另一个同行。

严格来说,WebRTC数据通道不是基于UDP的,而是基于SCTP的。但实际上,它们提供了实时数据交换所需的灵活性(例如,建立有利于低可靠性的连接的能力)。

服务器端组件使用数据通道的一个例子是


I'm making real time game for facebook. Now I broadcast state using websockets. But for real-time data udp is much better. I found out that there is WebRTC out there. But I can't use it because it's peer-to-peer and I want authoritative server(the one which runs physics and makes it harder to cheat).

I consider the following options:

  1. use flash sockets. But I have never used flash. Is it even possible to make a wrapper in javascript for flash udp? How hard is it? Does it require some special stuff on server side?
  2. maybe browser supports udp in some way? Can I stream video or audio to browser using udp? maybe it's possible to use video stream for my game state
  3. use websockets. I have some client-side prediction and I hope that latency would be below 100ms(even lower to be quite frank with you) - so maybe it's ok?
  4. use this WebRTC thing. maybe I can somehow simulate browser on server and use it as peer? For example run a bunch of chromes and send game data to them with websocket(no latency, they are on one machine) and then stream to clients over udp? But browsers can have limit on peer-to-peer connections and I need cpu on server to run physics

What is the best option? Have you implemented one of them and what was the result?

解决方案

You can definitely build or use a server-side component that will support WebRTC data channels; from the browser/client perspective, it will just be another peer.

Strictly speaking, WebRTC data channels aren't UDP based but SCTP based; but in practice, they provide the kind of flexibility you would need for real-time data exchange (with e.g. the ability to set up connections that favor low latency over reliability).

An example of a server-side component to use data channels would be https://www.npmjs.com/package/rtc-dcstream

这篇关于浏览器html5实时游戏。广播游戏状态选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 08:30