当尝试进行用户计数时,我得到错误的web socket is not in open state,我也有多租户的Saaskit,这会是原因吗?
我试过在startup.cs中指定UseWebsockets,但没有成功
{
private static int UserCount;
public override Task OnConnectedAsync()
{
UserCount++;
base.OnConnectedAsync();
this.Clients.All.SendAsync("updateUserCount", UserCount);
return Task.CompletedTask;
}
public override Task OnDisconnectedAsync(Exception exception)
{
UserCount--;
base.OnDisconnectedAsync(exception);
this.Clients.All.SendAsync("updateUserCount", UserCount);
return Task.CompletedTask;
}
}```
```<script>document.addEventListener('DOMContentLoaded', function () { } function onConnectionError(error) { if (error && error.message) { console.error(error.message); } } var connection = new signalR.HubConnectionBuilder().withUrl('/adminHub') .configureLogging(signalR.LogLevel.Debug).build(); connection.start() .then(function () { onConnected(connection); }) .catch(function (error) { console.error(error.message); });});`
调试:正在发送handshaenter code hereke请求。
调试:在start()过程中,集线器握手失败,错误为'WebSocket is not in the OPEN state‘。停止HubConnection。
处于断开连接状态时调用了HttpConnection.stopConnection(未定义)。
连接已断开,错误为'WebSocket is not the OPEN state‘。
处于连接状态时调用的HubConnection.connectionClosed(WebSocket未处于打开状态)。
发布于 2020-08-05 01:22:13
我知道这是迟来的回应,但这对我很有效:
在连接时调用start之后。
connection.start()
.then(function (data) {
console.log(data);
}).catch(function (err) {
console.log(err);
}); 将此属性添加到webSocket对象:
Object.defineProperty(window.WebSocket, 'OPEN', { value: 1, });https://stackoverflow.com/questions/57008745
复制相似问题