Visual Studio 的浏览器链接功能是否能够使用网络套接字? [英] Is Visual Studio's Browser Link feature able to use web sockets?

查看:20
本文介绍了Visual Studio 的浏览器链接功能是否能够使用网络套接字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我了解 SignalR 用于使用注入的动脉脚本与客户端浏览器进行通信.我有一个似乎很常见的问题,那就是我的浏览器的网络日志中充满了如下所示的条目:

I understand that SignalR is used to communicate with client browsers using the injected artery script. I have what seems to be a common problem, which is that my browser's network log is filled with entries that look like this:

.../arterySignalR/poll?transport=longPolling&connectionToken=...

.../arterySignalR/poll?transport=longPolling&connectionToken=...

这告诉我 SignalR 已经退回到长轮询而不是使用网络套接字.假设我们有一个支持 Web 套接字的浏览器,并且该浏览器在 localhost 上运行,那么 SignalR 不应该默认使用 Web 套接字吗?什么可能导致它回退到长轮询?

This tells me that SignalR has fallen back to long polling instead of using web sockets. Assuming that we have a browser that supports web sockets, and that browser is running on the localhost, shouldn't SignalR default to using web sockets? What might cause it to fall back to long polling?

推荐答案

简短回答

浏览器链接将仅在 Windows 8 或 Windows Server 2012 上使用 WebSockets

Browser Link will only use WebSockets on Windows 8 or Windows Server 2012

更长的答案

如果您在 Windows 7、Windows Vista 或 Windows Server 2008 上使用 Visual Studio,以下内容将解释该问题:

The following would explain the issue if you're using Visual Studio on Windows 7, Windows Vista or Windows Server 2008:

IIS (Express) 依赖于 System.Net.WebSockets 处理 WebSocket 连接;正如您在 MSDN 的链接中所读到的那样,当您在 Windows 7 上安装 .NET 4.5 时,您根本没有获得必要类的实际实现.

IIS (Express) depends on the .NET framework implementation in System.Net.WebSockets to handle WebSocket connections; as you can read in the link to MSDN, you simply don't get an actual implementation of the necessary classes when you install .NET 4.5 on Windows 7.

因此,在这种情况下,服务器无法同意客户端从标准 HTTP 更改为 WebSocket 协议的请求,这会强制 SignalR 客户端使用后备选项之一(在您的情况下:长轮询).

So in that case, the server can't agree to the client's request to change from standard HTTP to the WebSocket protocol, which forces the SignalR client to use one of the fallback options (in your case: long-polling).

这篇关于Visual Studio 的浏览器链接功能是否能够使用网络套接字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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