Flash 中的 WebSockets 与原始 TCP 套接字 [英] WebSockets vs raw TCP sockets in Flash

查看:26
本文介绍了Flash 中的 WebSockets 与原始 TCP 套接字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么 WebSockets 添加到原始 TCP 连接?为什么要使用 WebSockets?

What WebSockets add to raw TCP connection? Why should I use WebSockets?

我想听听这样的利弊:

  • 好:WebSockets 添加了一些有用的东西,例如自动重新连接、会话 ID 等.
  • 缺点:WebSockets 增加了很多开销

我将只有 Flash 客户端,不需要支持 Javascript 客户端.

I'll have only Flash clients, no need to support Javascript clients.

推荐答案

您无法在浏览器中从 Web 应用程序执行原始套接字.即使来自 Flash 的原始"套接字连接也不是真正原始的,因为您必须回答策略文件请求才能获得 CORS安全性(WebSockets 握手的部分原因).

You can't do raw sockets from a web application in a browser. Even "raw" socket connections from Flash are not really raw because you have to answer a policy file request to get CORS security (part of the reason for the WebSockets handshake).

在最初的 WebSocket 握手之后,WebSocket 消息每帧有两个字节的帧开销(Hixie-* 有 'x00...xff' 并且 HyBi-07 有两个字节的标头),所以开销相比之下可以忽略不计到常规套接字.

After the initial WebSocket handshake, WebSocket messages have two bytes of framing overhead per frame (Hixie-* has 'x00...xff' and HyBi-07 has two byte header), so the overhead is pretty negligible compared to regular sockets.

WebSocket 握手是 HTTP 兼容的升级请求,因此很容易将 WebSockets 支持集成到现有的 Web 服务器并使用现有的 Web 端口 (80/443),这意味着 WebSocket 连接也可以更轻松地集成到现有的防火墙规则中.

The WebSocket handshake is an HTTP compatible Upgrade request so it is easy to integrate WebSockets support into existing web servers and to use existing Web ports (80/443) which means that WebSocket connection can also more easily integrate into existing firewall rules.

HTTP 兼容握手​​还意味着现有的 HTTP 身份验证机制可以与 WebSockets 透明地工作.此外,WebSockets 可以由现有的 Web 代理代理,只需很少或无需修改.

The HTTP compatible handshake also means that existing HTTP authentication mechanisms can work transparently with WebSockets. Also, WebSockets can be proxied by existing web proxies with little or no modification.

在 WebSockets 协议修订版 (HyBi-07) 的下一个修订版中,它们是针对使用客户端到服务器对负载数据进行 XOR 掩码的行为不当的网络中介的保护.

In the next revision of the WebSockets protocol rev (HyBi-07), their is protection against misbehaving web intermediaries using client to server XOR masking of the payload data.

WebSockets 中没有定义自动重新连接、会话 ID 等内容,尽管一些构建在 WebSockets 上的 Javascript 框架具有此功能,例如 Socket.IO.如果您从 Flash 应用程序中执行 WebSockets,那么您需要进行自己的会话管理或转换现有的会话管理库以使用 WebSockets 而不是 Flash 套接字(这样非常容易转换).

Things like auto-reconnection, session ids, etc aren't defined in WebSockets although several Javascript frameworks built on WebSockets have this such as Socket.IO. If you are doing WebSockets from Flash applications then you would need to do your own session management or convert an existing session management library to use WebSockets rather than Flash sockets (such be pretty easy conversion).

更新:

几个可能对您或登陆此处的其他人有用的链接:

Couple of links that might be useful to you or others who land here:

  • AS3WebSocket:用于 Flash 应用程序的 WebSockets 客户端库.
  • web-socket-js:在 Flash 中为 Javascript 应用程序实现的 WebSockets 回退/polyfill(添加 WebSockets 支持到具有 Flash 但没有本机 WebSockets 的浏览器).
  • AS3WebSocket: WebSockets client library for Flash applications.
  • web-socket-js: WebSockets fallback/polyfill implemented in Flash for Javascript applications (to add WebSockets support to browsers with Flash but without native WebSockets).

这篇关于Flash 中的 WebSockets 与原始 TCP 套接字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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