.NET SignalR中长连接与HUB连接的使用方式以及区别
1 using Microsoft.AspNet.SignalR;
2 using System;
3 using System.Collections.Generic;
4 using System.Linq;
5 using System.Web;
6 using System.Web.UI;
7 using System.Web.UI.WebControls;
8
9 namespace WebApplication1
10 {
11 public partial class WebForm1 : System.Web.UI.Page
12 {
13 protected void Page_Load(object sender, EventArgs e)
14 {
15 //从外部访问类访问服务器上相对应的hub服务 方式a
16 var context=GlobalHost.ConnectionManager.GetHubContext<TestHub>();//管理连接到的Hub服务
17 context.Clients.All.recevie("该吃饭了");//只要是连接到该hub服务上的客户端都会调用客户端recevie方法
18
19 //从外部访问持久性连接服务 方式b
20 var connectionContext = GlobalHost.ConnectionManager.GetConnectionContext<TestConnection>();//管理相对应的持久性连接
21 connectionContext.Connection.Broadcast("该吃饭了");//向所有已连接的客户端发送信息
22
23 }
24 }
25 }
关注90後梦想大师,梦想从未止步.


浙公网安备 33010602011771号