博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
An Example of SignalR
阅读量:5062 次
发布时间:2019-06-12

本文共 2397 字,大约阅读时间需要 7 分钟。

SignalR can keep communication with the client and Server on real time. It`s a very wonderful independent tool for MVC development. 

Here I just finished an example by myself . And try to deepen my understanding in it.

SignalR was supported by the windows server 2012 that under the IIS 8 and .NET Framework4.5 environment. In the backaround, it`s 

support the WebSocket.   

At first, just try to add the package by Nuget

1. Microsoft.AspNet.SignalR  

2.Microsoft.AspNet.SignalR.Client

 

@{    ViewBag.Title = "Home Page";}

 

3. in view file support the last request as the source attacker.

You'd better bring the java script to your html file.

 pasting

4,   And a ProgressHub.cs as the following

 pasting

using Microsoft.AspNet.SignalR;using Microsoft.AspNet.SignalR.Hubs;using System.Threading.Tasks;using System.Threading;namespace WebApplication1{
[HubName("progress")] public class ProgressHub : Hub {
public int count = 1; public static void SendMessage(string msg, int count) {
var hubContext = GlobalHost.ConnectionManager.GetHubContext
(); hubContext.Clients.All.sendMessage(string.Format(msg), count); } public void GetCountAndMessage(string msg) {
ProgressStart(); Clients.Caller.sendMessage(string.Format(msg), count); } private void ProgressStart() {
Task.Run(() => {
for (int i=1; i<=100; i++) {
Thread.Sleep(500); SendMessage("処理中...", i); } }); } }}

 5. Edit the Startup.cs file.

 pasting

namespace WebApplication1{
public partial class Startup {
public void Configuration(IAppBuilder app) {
ConfigureAuth(app); app.MapSignalR(); // ← この行を追加 } }}

 

 References 

 https://github.com/SignalR/SignalR/tree/dev/src/Microsoft.AspNet.SignalR.Client.Portable

转载于:https://www.cnblogs.com/tomclock/p/7452806.html

你可能感兴趣的文章
C#Hashtable与Dictionary性能
查看>>
10个让你忘记 Flash 的 HTML5 应用演示
查看>>
SQL Server 使用作业设置定时任务之一(转载)
查看>>
Primary definition
查看>>
第二阶段冲刺-01
查看>>
BZOJ1045 HAOI2008 糖果传递
查看>>
发送请求时params和data的区别
查看>>
JavaScript 克隆数组
查看>>
eggs
查看>>
一步步学习微软InfoPath2010和SP2010--第七章节--从SP列表和业务数据连接接收数据(4)--外部项目选取器和业务数据连接...
查看>>
如何增强你的SharePoint 团队网站首页
查看>>
FZU 1914 Funny Positive Sequence(线性算法)
查看>>
oracle 报错ORA-12514: TNS:listener does not currently know of service requested in connec
查看>>
基于grunt构建的前端集成开发环境
查看>>
MySQL服务读取参数文件my.cnf的规律研究探索
查看>>
java string(转)
查看>>
__all__有趣的属性
查看>>
写博客
查看>>
利用循环播放dataurl的视频来防止锁屏:NoSleep.js
查看>>
python3 生成器与迭代器
查看>>