好啊。。。很明显现在我已经解决了:)
我的中心现在看起来是这样的:
public override Task OnConnectedAsync()
{
Interlocked.Increment(ref Count);
base.OnConnectedAsync();
Clients.All.SendAsync("updateCount", Count);
Clients.All.SendAsync("connected", Context.ConnectionId);
return Task.CompletedTask;
}
重要的一行是发送回连接id的那一行
Clients.All.SendAsync("connected", Context.ConnectionId);
在客户端,我监听“connected”并设置connectionid变量:
progressConnection.on("connected", (connectionId) => {
progressConnectionId = connectionId;
$("#connId").html(progressConnectionId);
$("#startButton").removeAttr("disabled");
$("#dropConnectionButton").removeAttr("disabled");
$("#openConnectionButton").attr("disabled", "disabled");
$("#msg").html("Connection established");
console.log("Connection Id: " + progressConnectionId);
});