简体   繁体   English

Websocket连接设置

[英]Websocket connection setup

I am trying to learn more about websocket and its internal implementations. 我想了解更多关于websocket及其内部实现的信息。 But still can'nt understand few things. 但仍然无法理解一些事情。 I tried googling for a in-depth explanation, but most of them just gives the high-level overview. 我尝试使用谷歌搜索进行深入解释,但大多数只是给出了高级概述。 Following are my doubts 以下是我的疑惑

1. According to what I read, web socket server (C# / C++ implementation) by default uses port 80. Although we can use any port, it's preferred that we use port 80 as we won't have any firewall issues. 1.据我所读,默认情况下,Web套接字服务器(C#/ C ++实现)使用端口80.虽然我们可以使用任何端口,但我们最好使用端口80,因为我们不会遇到任何防火墙问题。 If that's so, how are we supposed to run both the webserver and web socket server on the same port (80)? 如果是这样,我们如何在同一个端口(80)上运行web服务器和Web套接字服务器?

2. Let's assume that the web socket server is running on port 81 and webserver is running on port 80. 2.假设Web套接字服务器在端口81上运行,Web服务器在端口80上运行。

  1. So when the browser issues the initial handshake HTTP request (Upgrade: websocket) , this request sent to port 81. Right? 因此,当浏览器发出初始握手HTTP请求(Upgrade:websocket)时,此请求将发送到端口81.对吗? If so, this request (See below) does'nt have any relation to an HTTP protocol. 如果是这样,该请求(见下文)与HTTP协议没有任何关系。 But still we use HTTP protocol headers. 但我们仍然使用HTTP协议头。 Why? 为什么?

      GET /mychat HTTP/1.1 Host: server.example.com Upgrade: websocket Connection: Upgrade Sec-WebSocket-Key: x3JJHMbDL1EzLkh9GBhXDw== Sec-WebSocket-Protocol: chat Sec-WebSocket-Version: 13 Origin: http://example.com 
  2. Why dint they use the same websocket interface currently implemented in most browser to issue a direct TCP/IP connection with the given port, without any HTTP stuff? 为什么他们使用当前在大多数浏览器中实现的相同websocket接口来发出与给定端口的直接TCP / IP连接,而没有任何HTTP内容?

3. Is there any packet size limit or data/buffer limit for data sent/received from client/server? 3.对于从客户端/服务器发送/接收的数据,是否存在数据包大小限制或数据/缓冲区限制? If that's the case, do we need to frame the data and handle it ourselves? 如果是这种情况,我们是否需要构建数据并自行处理?

4. Does the websocket server always needs to be a separate service/process? 4. websocket服务器是否总是需要是一个单独的服务/流程? In future will the webserver's (IIS, apache) will include support for hosting web socket servers within its process space? 将来网络服务器(IIS,apache)将包括在其进程空间内托管Web套接字服务器的支持吗?

  1. By using an HTTP compatible handshake you can integrate a WebSocket handler into your webserver or just have the webserver forward the websocket connection to a dedicated WebSocket server. 通过使用HTTP兼容握手,您可以将WebSocket处理程序集成到Web服务器中,或者让Web服务器将websocket连接转发到专用WebSocket服务器。

  2. The WebSocket handshake uses an HTTP compatible handshake to allow both protocols to be handled easily on the same port and it allows existing firewall configurations to much more easily support WebSocket traffic. WebSocket握手使用HTTP兼容握手,允许在同一端口上轻松处理这两种协议,并允许现有防火墙配置更轻松地支持WebSocket流量。 In addition, preventing cross-side script attacks in well understood in the context of HTTP requests and so WebSocket leverages that knowledge. 此外,防止在HTTP请求的上下文中充分理解的跨端脚本攻击,因此WebSocket利用了这些知识。 Even after the connection is established, WebSocket is not a raw socket connection. 即使在建立连接之后,WebSocket 也不是原始套接字连接。 It is a message based protocol and therefore requires framing. 它是基于消息的协议,因此需要框架。 In addition, the framing is masked when sent from client (browser) to server in order to alleviate fears of a theoretical vulnerability in misbehaving proxies/caches/intermediaries. 此外,当从客户端(浏览器)发送到服务器时,框架被屏蔽,以减轻对行为不当的代理/缓存/中介的理论漏洞的担忧。

  3. There is no limit on message size in the protocol itself. 协议本身的消息大小没有限制。 A message can be split into multiple frames. 消息可以拆分为多个帧。 There is a protocol limit to frame size but it's 2^64 bytes. 帧大小存在协议限制,但它是2 ^ 64字节。 The actual frame size limit will be smaller depending on client/server implementation. 根据客户端/服务器实现,实际帧大小限制将更小。 If you have multi-megabyte single messages that you want to send you might consider changing your application to use smaller messages to maximize cross-browser and cross-server support. 如果您要发送多兆字节的单个邮件,则可以考虑更改应用程序以使用较小的邮件,以最大限度地提高跨浏览器和跨服务器的支持。

  4. WebSocket handling can definitely be integrated into web servers and this was very much a scenario envisioned by the working group. WebSocket处理绝对可以集成到Web服务器中,这是工作组设想的非常多的场景。 For example, consider pywebsocket which is designed to run both standalone or as a mod_python module in Apache. 例如,考虑pywebsocket ,它被设计为独立运行或作为Apache中的mod_python模块运行。 As another example, ASP.NET 4.5 and IIS 8 will have built-in support for WebSockets . 另一个例子是, ASP.NET 4.5和IIS 8将内置对WebSockets的支持

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM