WebSockets 真的要由 Web 服务器处理吗? [英] Are WebSockets really meant to be handled by Web servers?

查看:33
本文介绍了WebSockets 真的要由 Web 服务器处理吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

WebSocket 标准尚未得到批准,但从草案看来,该技术旨在在 Web 服务器中实现.pywebsocket 实现了一个 WebSocket 服务器,它可以是专用的,也可以作为 Apache 插件加载.

The WebSocket standard hasn't been ratified yet, however from the draft it appears that the technology is meant to be implemented in Web servers. pywebsocket implements a WebSocket server which can be dedicated or loaded as Apache plugin.

所以我想知道的是:WebSockets 的理想用途是什么?使用专用的 WebSocket 服务器来实现服务是否有意义,还是重新考虑将其运行在支持 WebSocket 的 Web 服务器之上是否更好?

So what I am am wondering is: what's the ideal use of WebSockets? Does it make any sense to implement a service using as dedicated WebSocket servers or is it better to rethink it to run on top of WebSocket-enabled Web server?

推荐答案

WebSocket 协议的设计考虑了三种模型:

The WebSocket protocol was designed with three models in mind:

  • 一个完全独立于任何网络服务器运行的 WebSocket 服务器.
  • 一个与 Web 服务器分开运行的 WebSocket 服务器,但将流量从 Web 服务器代理到 WebSocket 服务器(允许 WebSocket 和 HTTP 流量在同一端口上共存)
  • 在 Web 服务器中作为插件运行的 WebSocket 服务器.

您选择的模型实际上取决于您尝试构建的应用程序以及可能会限制您选择的其他一些限制条件.

The model you pick really depends on the application you are trying to build and some other constraints that may limit your choices.

例如,如果您的应用程序将从单个 Web 服务器提供服务,并且 WebSocket 连接将始终返回到同一台服务器,那么将 WebSocket 服务器作为插件/模块运行在网络服务器.

For example, if your application is going to be served from a single web server and the WebSocket connection will always be back to that same server, then it probably makes sense to just run the WebSocket server as a plugin/module in the web server.

另一方面,如果您有一个可从许多不同网站使用的通用 WebSocket 服务(例如,您可以从 WebSocket 服务器提供持续的低延迟流量更新),那么您可能想要运行 WebSocket服务器与任何网络服务器分开.

On the other hand if you have a general WebSocket service that is usable from many different web sites (for example, you could have continuous low-latency traffic updates served from a WebSocket server), then you probably want to run the WebSocket server separate from any web server.

基本上,WebSocket 服务和 Web 服务之间的集成越紧密,您就越有可能希望在同一端口上一起运行它们.

Basically, the tighter the integration between your WebSocket service and your web service, the more likely you will want to run them together and on the same port.

有一些约束可能会强制使用一种或另一种模型:

There are some constraints that may force one model or another:

  • 如果您控制服务器而不是传入的防火墙规则,那么您可能别无选择,只能在与 HTTP/HTTPS 服务器相同的端口(例如 80 和 443)上运行 WebSocket 服务器.在这种情况下,您将不得不使用 Web 服务器插件或代理来访问真正的 WebSocket 服务器.
  • 另一方面,如果您在运行 WebSocket 服务器的服务器上没有超级用户权限,那么您可能无法使用端口 80 和 443(1024 以下通常是特权端口范围)) 并且在这种情况下,您是否在同一端口上运行 HTTP/S 和 WebSocket 服务器并不重要.
  • 如果您在 Web 服务器中有基于 cookie 的身份验证(例如 OAuth),并且您想将其重新用于 WebSocket 连接,那么您可能希望将它们一起运行(紧密集成的特殊情况).

这篇关于WebSockets 真的要由 Web 服务器处理吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆