WebSockets与Flash中的原始TCP套接字

时间:2021-05-04 22:30:03

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

WebSockets添加到原始TCP连接的内容是什么?我为什么要使用WebSockets?

I'd like to hear cons and pros like:

我想听听利弊和专业人士的喜欢:

  • Good: WebSockets add some useful things like autoreconnection, session ids, etc.
  • 好:WebSockets添加一些有用的东西,如自动连接,会话ID等。
  • Bad: WebSockets add a lot of overhead
  • 坏:WebSockets增加了很多开销

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

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

1 个解决方案

#1


17  

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).

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

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握手之后,WebSocket消息每帧有两个字节的帧开销(Hixie- *有'\ x00 ... \ xff'而HyBi-07有两个字节的头),所以与常规套接字相比,开销几乎可以忽略不计。

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.

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

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.

HTTP兼容握手还意味着现有的HTTP身份验证机制可以与WebSockets透明地工作。此外,WebSockets可以由现有的Web代理代理,几乎不需要修改。

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协议版本(HyBi-07)的下一版本中,它们可以防止使用客户端对服务器XOR屏蔽有效载荷数据的行为不当的Web中介。

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).

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

Update:

更新:

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

可能对您或其他人员有用的链接:

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

#1


17  

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).

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

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握手之后,WebSocket消息每帧有两个字节的帧开销(Hixie- *有'\ x00 ... \ xff'而HyBi-07有两个字节的头),所以与常规套接字相比,开销几乎可以忽略不计。

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.

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

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.

HTTP兼容握手还意味着现有的HTTP身份验证机制可以与WebSockets透明地工作。此外,WebSockets可以由现有的Web代理代理,几乎不需要修改。

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协议版本(HyBi-07)的下一版本中,它们可以防止使用客户端对服务器XOR屏蔽有效载荷数据的行为不当的Web中介。

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).

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

Update:

更新:

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

可能对您或其他人员有用的链接:

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