【问题标题】:SignalR works only on localhostSignalR 仅适用于本地主机
【发布时间】:2016-10-11 08:24:03
【问题描述】:

在我的 SignalR 客户端中,我有以下 javaScript 库:

<!--Reference the jQuery library. -->
<script src="Scripts/jquery-1.6.4.min.js"></script>
<!--Reference the SignalR library. -->
<script src="Scripts/jquery.signalR-2.2.1.min.js"></script>
<!--Reference the autogenerated SignalR hub script. -->
<script src="http://localhost:8081/signalr/hubs"></script>

在 Javascript 中我去:

$.connection.hub.url = "http://localhost:8081/signalr;
$.connection.hub.logging = true;
var push = $.connection.exosChangeNotifier;
...
$.connection.hub.start().done();

连接与 localhost 配合得很好。 当我在 VM 或另一台计算机上运行 SignalR 集线器并将 localhost 替换为 ip 地址或计算机名称时,我得到一个

http://[servername]:8081/signalr/hubs Failed to load resource: the server responded with a status of 400 (Bad Request)
Uncaught TypeError: Cannot read property 'client' of undefined.

我在我的计算机上的防火墙上打开了端口 8081 作为传出规则和远程计算机或 VM 上的传入规则。使用 Sysinternal psping 我验证了端口是可访问的:

psping.exe [servername]:8081 -h

通过Powershell Script,我能够仔细检查计算机是否可以访问并且端口是否打开。

在自托管 SignalR 启动中,我启用了 CORS:

map.UseCors(CorsOptions.AllowAll);

我错过了什么?

【问题讨论】:

  • 你也在服务器上使用8081端口吗?
  • 是的。 8081在Server和Client上使用,否则本地使用就不行了。
  • 看来你只需要找出正确的 url 就可以了,这是外界没有人可以帮助你的......
  • 我在this SO Question 中找到了解决方案。服务器必须以 http://*:8081 启动才能响应内部和外部请求。

标签: signalr owin self-hosting


【解决方案1】:

我在this SO Question 中找到了解决方案。服务器必须以 http://*:8081 启动以响应内部和外部请求。之前它被设置为只听本地主机。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-11-16
    • 2017-02-25
    • 2023-04-05
    • 2023-03-31
    • 1970-01-01
    • 2011-03-30
    • 2012-10-08
    • 1970-01-01
    相关资源
    最近更新 更多