2013年9月16日 星期一

ASP.NET SignalR – Hubs

 

Hubs Concept

image

image

image

Convention: 慣例,常規,習俗,公約,協定。For example, Coding Convention.

image

 

Programming Model

image

Context: 文章脈絡,事件的來龍去脈

image

 

Demo

image

image

image

image

 

Hubs Protocol

image

image

image

image

 

 

1. .NET 4.0 doesn’t support WebSocket, so it will use SSE (Server Send Event) as second priority

2. .NET 4.5 support WebSocket, so it will directly use it as first priority

image

image

 

Step 1: Negotiate, try WebSockets

Step 2.1: Connect, with WebSockets, but fail

Step 2.2: Connect again, with SSE, success

image

image

 

If change <httpRuntime targetFramework=”4.5” /> in web.config, WebSocket will be used

image

 

Force using LongPolling as transport negociation

image

image

 

Pushing Data: Clients

image

 

image

Clients.Others

Clients.AllExcept(Context.ConnectionId)

above 2 are equal too.

 

Pushing Data: Groups

image

image

 

Demo – JoinRoom(), SendMessageToRoom()

image

image

 

Hub Lifecycle

image

image

 

Demo

image

image

New a class, MonitorHub.cs

image

GlobalHost.ConnectionManager.GetHubContext<T>();

image

 

Summary

image

沒有留言:

張貼留言