- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 localhost:5005
上运行 websokets 模块的 python websocket 服务器。来自 documentation page 的代码:
#!/usr/bin/env python
import asyncio
import websockets
import logging
logger = logging.getLogger('websockets')
logger.setLevel(logging.DEBUG)
logger.addHandler(logging.StreamHandler())
async def echo(websocket):
async for message in websocket:
print(message)
await websocket.send(message)
async def main():
async with websockets.serve(echo, "localhost", 5005):
await asyncio.Future() # run forever
asyncio.run(main())
客户端可以通过连接到 URL ws://localhost:5005
来访问它。 websockets 模块中提供了示例客户端代码 documentation page .
目标 是使客户端能够通过充当反向代理的 IIS(Windows native 网络服务器)访问服务器,即通过 URL ws://localhost/app
。
IIS-10 设置:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="ReverseProxy" stopProcessing="true">
<match url="(.*)" />
<action type="Rewrite" url="http://localhost:5005" logRewrittenUrl="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
一旦客户端尝试连接,它就会断开连接并且服务器抛出此异常:
= connection is CONNECTING
< GET / HTTP/1.1
< Cache-Control: no-cache
< Connection: Upgrade
< Pragma: no-cache
< Upgrade: websocket
< Accept-Encoding: gzip, deflate, br, peerdist
< Accept-Language: en-US,en;q=0.9
< Host: localhost:5005
< Max-Forwards: 10
< User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36
< Origin: null
< Sec-WebSocket-Version: 13
< Sec-WebSocket-Key: /C9ah/z+wAo4mnoACSz2IA==
< Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits
< X-Original-URL: /app
< X-Forwarded-For: [::1]:52798
< X-ARR-LOG-ID: 8c59749a-4e5d-43cf-8a5a-c4421cc4ecc8
< X-P2P-PeerDist: Version=1.1
< X-P2P-PeerDistEx: MinContentInformation=1.0, MaxContentInformation=2.0
> HTTP/1.1 101 Switching Protocols
> Upgrade: websocket
> Connection: Upgrade
> Sec-WebSocket-Accept: W9Sttf7fHX3aB9zd4b/PVGt0Ldg=
> Sec-WebSocket-Extensions: permessage-deflate; server_max_window_bits=12; client_max_window_bits=12
> Date: Fri, 15 Jul 2022 19:14:32 GMT
> Server: Python/3.7 websockets/10.3
connection open
= connection is OPEN
! failing connection with code 1006
= connection is CLOSED
x half-closing TCP connection
connection handler failed
Traceback (most recent call last):
File "C:\Users\amin.ramezanifar\AppData\Roaming\Python\Python37\site-packages\websockets\legacy\protocol.py", line 945, in transfer_data
message = await self.read_message()
File "C:\Users\amin.ramezanifar\AppData\Roaming\Python\Python37\site-packages\websockets\legacy\protocol.py", line 1015, in read_message
frame = await self.read_data_frame(max_size=self.max_size)
File "C:\Users\amin.ramezanifar\AppData\Roaming\Python\Python37\site-packages\websockets\legacy\protocol.py", line 1090, in read_data_frame
frame = await self.read_frame(max_size)
File "C:\Users\amin.ramezanifar\AppData\Roaming\Python\Python37\site-packages\websockets\legacy\protocol.py", line 1149, in read_frame
extensions=self.extensions,
File "C:\Users\amin.ramezanifar\AppData\Roaming\Python\Python37\site-packages\websockets\legacy\framing.py", line 70, in read
data = await reader(2)
File "C:\Program Files\Python37\lib\asyncio\streams.py", line 677, in readexactly
raise IncompleteReadError(incomplete, n)
asyncio.streams.IncompleteReadError: 0 bytes read on a total of 2 expected bytes
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\amin.ramezanifar\AppData\Roaming\Python\Python37\site-packages\websockets\legacy\server.py", line 232, in handler
await self.ws_handler(self)
File "D:/Robotic Framework/RoboticApps/UI_Framework/server.py", line 12, in echo
async for message in websocket:
File "C:\Users\amin.ramezanifar\AppData\Roaming\Python\Python37\site-packages\websockets\legacy\protocol.py", line 482, in __aiter__
yield await self.recv()
File "C:\Users\amin.ramezanifar\AppData\Roaming\Python\Python37\site-packages\websockets\legacy\protocol.py", line 553, in recv
await self.ensure_open()
File "C:\Users\amin.ramezanifar\AppData\Roaming\Python\Python37\site-packages\websockets\legacy\protocol.py", line 921, in ensure_open
raise self.connection_closed_exc()
websockets.exceptions.ConnectionClosedError: no close frame received or sent
connection closed
为了确保 IIS 设置是否正确,我使用了来自 here 的另一个名为“simple-websocket-server”的 websocket 库它工作正常。我还尝试了来自 here 的简单 Node.js 服务器并且成功了。
有什么问题吗?
最佳答案
Amin(问题作者)和我发现您必须在 websockets 中禁用压缩,因为 IIS 不支持它。
与 websockets 不同,它与其他库一起工作,因为它们不实现压缩或默认情况下不启用它。
详情参见GitHub上的讨论:https://github.com/aaugustin/websockets/issues/1192
关于Python websockets 模块和 IIS 作为反向代理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73008159/
当我查看 IIS 日志文件时,我可以在一天中的不同时间看到标题行被写入日志文件。我唯一一次看到这种情况发生是在 IIS 重置时;或启动。 例如下面的标题行; #Software: Microsoft
有谁知道为什么以下 web.conig 更改不起作用: 在我添加 javascript 文件后仍然没有被压缩(gzip)。我折腾了几天,因为一开始我真的不知道问题是
目前,我们所有的网络应用程序都将其应用程序池标识设置为 ApplicationPoolIdentity。现在,当一个应用程序需要访问某些服务器上的某些资源时,比如添加/读取某些文件,该应用程序会在代码
在 IIS(特别是 6.0)中,在“主目录”选项卡下,如果我更改本地路径,是否会导致 IIS 重新启动或应用程序池回收? 相关的,是否有概述 IIS 元数据库的哪些更改将触发重新启动或应用程序池回收的
只要更改了任何 web.config 文件,AFAIK IIS 就会重新启动。 我创建了自己的配置文件(my.config,层次结构略有不同)。是否有可能让 IIS 自动(自动神奇地 :))重新启动,
你好, 我正在寻找 IIS 日志中列出的浏览器条目列表,以帮助识别访问我们网站的不同版本的浏览器。也许没有一个列表,而是一个应该用来识别不同浏览器及其版本的算法。 请注意,我不是在寻找日志分析器,而是
我想知道上次重新启动 iis 是什么时候。 IIS 是否保留了此日志,我在哪里可以找到此日志? 谢谢 最佳答案 打开事件查看器,导航到“Windows 日志”->“系统” 在右侧的“操作” Pane
在全新安装的带有 IIS 7 的 Windows Server 2008 R2 上,它会在 C:\inetpub\wwwroot 中创建一个默认网站。 .我确信对于存储网站文件的好位置有很多主观意见,
我已按照 this question 中的说明在 IIS 中实现动态内容压缩。 . 当我发送请求时,我看不到响应被 gzip 压缩的任何证据: IIS版本为7.5 有什么明显的我应该检查以解决此问题吗
这是场景: 服务器 A 托管“主”应用程序 (www.example.com) 服务器 B 托管支持应用程序 (b.example.com) 它们通过 192.* 地址在内部相互连接,并且都可以通过
是否有任何替代 IIS 管理 UI 可用于从程序重置 IIS?.. 现在我们已经创建了一个批处理文件,如果 iis 重置并每小时安排一次...... 我只是想要一些东西,这样我们就不能重置 iis..
我的 Windows Server 在 IIS 7.5 上运行 Web 应用程序。 我想知道为什么 IIS 应用程序池使用大量内存。 请参阅我从服务器捕获的屏幕截图。 在名为 TEST 2.0(.NE
我在 IIS 7.5 上运行的 ASP Classic 站点上收到服务器错误。 我将“向浏览器发送错误”设置为 True ,但是我仍然收到以下错误屏幕: 最佳答案 IIS 正在劫持您的经典 ASP 应
我正在尝试通过IIS上的反向代理连接到websockets服务器(websockify)。 IIS和Websockets服务器位于同一台物理服务器上(Windows Server 2012 R2,II
我需要让我的开发机器从本地机器商店读取证书 为此,我需要运行winhttpcertcfg.exe并指定我要提升的帐户 该帐户用于IIS表示什么? (对于IIS,它将是IWAM_MachineName)
我正在阅读特定命令(SET-WEBCONFIGURATIONPROPERTY),但出现"is not recognized as a cmdlet"错误。给我的建议是,即使我使用的是SharePoin
我已经为 IIS8 安装了静态和动态压缩并启用了它。 当我的CPU性能100%时,我的GZIP IIS不工作,为什么? 我可以清楚地看到 GZIP 没有在 Live HTTP header 中运行。我
我已经从官方镜像(https://hub.docker.com/r/microsoft/iis/)运行了IIS 在Windows Server 2016上 有什么方法可以从IIS管理器连接到该IIS,
你好, 如果 iis 未运行,我想编写一个状态为的代码。 最佳答案 从命令行启动 IIS: iisreset /start 从命令行停止 IIS: iisreset /stop 重新启动(停止和启动)
我已经为 IIS8 安装了静态和动态压缩并启用了它。 当我的CPU性能100%时,我的GZIP IIS不工作,为什么? 我可以清楚地看到 GZIP 没有在 Live HTTP header 中运行。我
我是一名优秀的程序员,十分优秀!