Are WebSockets really meant to be handled by Web servers?

前端 未结 1 1138
无人共我
无人共我 2021-02-02 00:06

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 WebSo

相关标签:
1条回答
  • 2021-02-02 00:33

    The WebSocket protocol was designed with three models in mind:

    • A WebSocket server running completely separately from any web server.
    • A WebSocket server running separately from a web server, but with traffic proxied to the websocket server from the web server (allowing websocket and HTTP traffic to co-exist on the same port)
    • A WebSocket server running as a plugin in the web server.

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

    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.

    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.

    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:

    • If you control the server(s) but not the incoming firewall rules, then you probably have no choice but to run the WebSocket server on the same port(s) as your HTTP/HTTPS server (e.g. 80 and 443). In which case you will have to use a web server plugin or proxy to the real WebSocket server.
    • On the other hand, if you do not have super-user permission on the server where you are running the WebSocket server, then you will probably not be able to use ports 80 and 443 (below 1024 is generally a privileged port range) and in that case it really doesn't matter whether you run the HTTP/S and WebSocket servers on the same port or not.
    • If you have cookie based authentication (such as OAuth) in the web server and you would like to re-use this for the WebSocket connections then you will probably want to run them together (special case of tight integration).
    0 讨论(0)
提交回复
热议问题