3

我想开始创建一个在手机(任何类型的智能手机)上打开的网站。该网站将具有控制您已在计算机上打开的网站的功能。(2011年的大众新世纪甲壳虫有一个功能,我可以通过智能手机在我的台式电脑上打开的网站上滚动)

我们有一个马视频流媒体网站,这对我们的客户来说将是一个很棒的功能,如果他们可以在他们的智能电视上观看流媒体并通过 iphone/android/wp 进行控制。

来自瑞士的 wilmaa.com 还为智能手机提供了遥控器,可以在智能电视/网络浏览器上浏览我的网站。

因为我需要一个起点来了解它是如何工作的,所以我正在检查谷歌,也许外面已经有任何遥控器,但不幸的是我什么也找不到。

也许 Stack Overflow 可以通过提供一些关于如何实现这一点的起点来帮助我。

4

1 回答 1

6

To do this you need some kind of 'pushing' service able to overcome the inherent drawback of HTTP that it has always been a 'pull only' system - client initiates a request, server answers. In this case you want to push an event from the server to the client.

For the past years this has been done with so called 'long polling'. This means that you 'abuse' the mechanism present in browsers that protects the server from hanging requests, but allows them to take a while. Apache is by default configured to allow a request to last 300 seconds on most platforms. Long polling works by sending an Ajax request, and if the server has no data, instead of sending that back it just waits, until either it does have data, or a long period such as a minute has expired. The client does not send a new request until it has received a response. This gives the illusion to the end user of real time feedback, and is how sites like Facebook et al have done this for years.

Since a few months it's also possible to employ a new HTML5 technology that now has stable implementations on all major browsers: Websockets. This technology allows a server to upgrade a common pull request to a full bidirectional connection, allowing realtime communication between browser and server. Regrettably, the 'regular' webservers such as Apache are not really built for this kind of logic, although it is possible to emulate it with frameworks like Ratchet. For the realtime part of the system the current platform of choice for most sites, including Stack Overflow here, is node.js - serverside asynchronous Javascript.

What I would recommend in your situation:

  • Set up a separate node.js server as an event dispatcher (you can get a cheap micro sized EC2 instance at Amazon for like $15 per month which will probably suffice, and is very scalable)
  • Keep all the other code in the regular environment where it is now, just add logic to communicate with the event dispatcher
  • Deploy Socket.io as your websocket handling service. It simplifies all the Javascript logic on both server and client side, and wraps a realtime connection in such a way that it's even compatible with IE5.5, by gracefully degrading towards technologies that are supported by both server and client - websockets on recent browsers, long polls or other technologies on legacy systems.

With this solution you can easily implement, with relatively little code, a system with full realtime responsiveness across multiple platforms as you described.

As for the controlling app itself, just use HTML5, with Phonegap if you intend to distribute to app stores.

于 2013-05-04T09:44:09.807 回答