.net signalr 的hub和PersistentConnection两种方式,除了写法不一样外,还有其他不一样么?或者说,这两种方式各偏重哪一部分?
.net signalr 的hub和PersistentConnection两种方式,除了写法不一样外,还有其他不一样么?或者说,这两种方式各偏重哪一部分?
你可以简单理解,就是connection更原始,你要是用的话就用hub就行了。
connectino提供了直接访问底层通信协议。
如果你需要做双工的话直接用hub。
这个是官方文档的区别
Connections and Hubs
The SignalR API contains two models for communicating between clients and servers: Persistent Connections and Hubs.
A Connection represents a simple endpoint for sending single-recipient, grouped, or broadcast messages. The Persistent Connection API (represented in .NET code by the PersistentConnection class) gives the developer direct access to the low-level communication protocol that SignalR exposes. Using the Connections communication model will be familiar to developers who have used connection-based APIs such as Windows Communcation Foundation.
A Hub is a more high-level pipeline built upon the Connection API that allows your client and server to call methods on each other directly. SignalR handles the dispatching across machine boundaries as if by magic, allowing clients to call methods on the server as easily as local methods, and vice versa. Using the Hubs communication model will be familiar to developers who have used remote invocation APIs such as .NET Remoting. Using a Hub also allows you to pass strongly typed parameters to methods, enabling model binding.
看文档
https://docs.microsoft.com/en...