如何从 Web 浏览器(客户端)建立 TCP 套接字连接? [英] How to establish a TCP Socket connection from a web browser (client side)?

查看:82
本文介绍了如何从 Web 浏览器(客户端)建立 TCP 套接字连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了有关 WebSockets 的内容,但它们似乎不是纯粹的套接字",因为它们之上有一个应用层协议."ws:"

I've read about WebSockets but they don't seem to be pure "sockets", because there is an application layer protocol over them. "ws:"

有没有办法从网络浏览器进行纯套接字连接,让网页更加生动?

Is there any way of doing a pure socket connection from a web browser, to enliven webpages?

这是我在黑暗中的随机刺

Here are my random stabs in the dark

  • Java 提供的小程序套接字(需要安装 java)
  • Flash 提供的 Flash 插槽(需要安装 Flash)

但是关于 HTML5,如果它们不是 Sockets,为什么要称为 WebSockets?

But about HTML5, Why are they called WebSockets if they aren't Sockets?

websocket 协议实现起来是否如此简单以至于几乎"是套接字?

Is the websocket protocol so simple to implement that it is "almost"-sockets?

推荐答案

我读过有关 WebSockets 的文章,但它们似乎不是纯粹的套接字",因为它们之上有一个应用层协议.

I've read about WebSockets but they don't seem to be pure "sockets", because there is an application layer protocol over them.

[是] websocket 协议实现起来如此简单以至于[它]几乎"是-sockets?

[Is the] websocket protocol so simple to implement that [it is] "almost"-sockets?

允许直接来自浏览器的常规套接字连接永远不会发生,因为这会带来巨大的风险.WebSockets 与您将要获得的浏览器中的原始套接字一样接近.最初的 WebSockets 握手类似于 HTTP 握手(允许 Web 服务器代理/桥接它)并添加 CORS 类型安全性.此外,WebSockets 是一种基于消息的传输(而不是作为原始 TCP 流式传输),这是通过在每个消息帧上使用两个字节的标头来完成的.

Allowing regular socket connections directly from the browser is never going to happen because it opens up a huge risk. WebSockets is about as close to raw sockets from the browser as you are going to get. The initial WebSockets handshake is similar to an HTTP handshake (allowing web servers to proxy/bridge it) and adds CORS type security. In addition, WebSockets is a message based transport (rather than streaming as raw TCP) and this is done using a two byte header on each message frame.

即使是闪存也不能完全建立原始 TCP 连接.闪存套接字还增加了 CORS 安全性,但不是带内握手,而是闪存套接字连接连接到目标服务器上的端口 843 以请求安全策略文件.

Even flash is not able to quite make raw TCP connections. Flash sockets also add CORS security, but instead of an in-band handshake, flash socket connections make a connection to port 843 on the target server to request a security policy file.

有没有办法从网络浏览器进行纯套接字连接,让网页更加生动?

Is there any way of doing a pure socket connection from a web browser, to enliven webpages?

是的,您可以使用我的 websockify 桥接/代理,它允许启用 WebSockets 的浏览器通过 websockify 直接连接到 TCP 套接字.

Yes, you can use my websockify bridge/proxy which allows a WebSockets enabled browser to connect directly to a TCP socket via websockify.

但是关于 HTML5,如果它们不是 Sockets,为什么它们被称为 WebSockets?

But about HTML5, Why are they called WebSockets if they aren't Sockets?

WebSockets 是一种建立在 TCP 套接字上的传输.握手后的开销非常小(通常只有两个字节的标头).

WebSockets are a transport built on TCP sockets. After the handshake there is very minimal overhead (typically just a two byte header).

这篇关于如何从 Web 浏览器(客户端)建立 TCP 套接字连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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