聊天demo SignalR
1首先这个demo是针对 net版本是4.5的 SignalR 获取的是2.2的
2新建一个mvc项目
3 Nuget 搜索 SignalR 安装如图的一项

4新建一个 集线器类

修改新建的 类
[HubName("demo")]
public class ChatHub:Hub
{
public void Send(string name, string message)
{
// Call the addNewMessageToPage method to update clients.
Clients.All.addNewMessageToPage(name, message);
}
}
5 Startup修改
public void Configuration(IAppBuilder app)
{
//ConfigureAuth(app);
app.MapSignalR();
}
6 在home/index中
<div class="container">
<input type="text" id="message" />
<input type="button" tabindex="1" id="sendmessage" value="Send" />
<input type="hidden" id="displayname" />
<ul id="discussion"></ul>
</div> @section scripts {
<!--Script references. -->
<!--The jQuery library is required and is referenced by default in _Layout.cshtml. -->
<!--Reference the SignalR library. -->
@*<script src="~/Scripts/jquery.signalR-1.0.1.js"></script>*@
<script src="~/Scripts/jquery-1.10.2.js"></script>
<script src="~/Scripts/jquery.signalR-2.2.0.js"></script> <script src="~/signalr/hubs"></script>
<!--Reference the autogenerated SignalR hub script. -->
<!--SignalR script to update the chat page and send messages.-->
<script>
$(function () {
// Reference the auto-generated proxy for the hub.
var chat = $.connection.demo;
// Create a function that the hub can call back to display messages.
chat.client.addNewMessageToPage = function (name, message) {
// Add the message to the page.
$('#discussion').append('<li><strong>' + htmlEncode(name)
+ '</strong>: ' + htmlEncode(message) + '</li>');
};
// Get the user name and store it to prepend to messages.
$('#displayname').val(prompt('Enter your name:', ''));
// Set initial focus to message input box.
$('#message').focus();
// Start the connection.
$.connection.hub.start().done(function () {
$('#sendmessage').click(function () {
// Call the Send method on the hub.
chat.server.send($('#displayname').val(), $('#message').val());
// Clear text box and reset focus for next comment.
$('#message').val('').focus();
});
});
});
// This optional function html-encodes messages for display in the page.
function htmlEncode(value) {
var encodedValue = $('<div />').text(value).html();
return encodedValue;
}
</script>
}
这个是官网的demo 就是展示界面 没什么好说的
另外附上 官网 下载zip 所有强大的功能都有!!
该项目demo
聊天demo SignalR的更多相关文章
- 视频聊天 Demo
ESFramework Demo -- 入门Demo,简单的即时通讯系统(附源码) 是基于ESFramework实现的一个简单的文字聊天demo,现在,我们将在这个demo的基础上,使用OMCS为其增 ...
- 一个基于netty的websocket聊天demo
这里,仅仅是一个demo,模拟客户基于浏览器咨询卖家问题的场景,但是,这里的demo中,卖家不是人,是基于netty的程序(我就叫你uglyRobot吧),自动回复了客户问的问题. 项目特点如下: 1 ...
- 基于websocket vue 聊天demo 解决方案
基于websocket vue 聊天demo 解决方案 demo 背景 电商后台管理的客服 相关技术 vuex axios vue websocket 聊天几种模型 一对一模型 一对一 消息只一个客户 ...
- 含服务端,客户端,数据库的注册/登录/聊天/在线/离线查看的聊天demo
用websocket,mysql,node的写了一个简单聊天的demo 实现了: 注册,登陆功能: 聊天信息广播: 在线/离线状态的查看: 服务端: 主要引用http,fs,mysql,socket. ...
- 仿微信 即时聊天工具 - SignalR (一)
话不多说,先上图 背景: 微信聊天,经常会遇见视频发不了,嗯,还有聊天不方便的问题,于是我就自己买了服务器,部署了一套可以直接在微信打开的网页进行聊天,这样只需要发送个url给朋友,就能聊天了! 由于 ...
- 使用GatewayWorker 开发个即时聊天demo
前言: 上手册以示尊重:https://www.kancloud.cn/walkor/gateway-worker/326138: https://www.cnblogs.com/fuqiang88/ ...
- WebIM 聊天 Demo
最近 2 个月用业余时间写了一个 IM ,动手之前想了很多,包括前期设计.语言.数据库等,经过了一番思想斗争,最终前台用 Vue.js 展示,Server 使用 node ,数据库使用 MongoDB ...
- ios 聊天demo 和nsoperationdemo
http://blog.csdn.net/zhibudefeng/article/details/7991649 http://blog.csdn.net/kangx6/article/details ...
- SignalR来做实时Web聊天
本章和大家分享的内容是使用Signal R框架创建个简易的群聊功能,主要讲解如何在.Net的MVC中使用这个框架,由于这个项目有官方文档(当然全英文),后面也不打算写分享篇了,主要目的是让朋友们在需要 ...
随机推荐
- Citrix 服务器虚拟化之三十二 XenConvert
Citrix 服务器虚拟化之三十二 XenConvert 简介: Citrix XenConvert 是用于实现物理到虚拟(P2V)转换的工具,可将工作负载从运行 Windows 的服务器或桌面计算 ...
- Element.Event
addEvent(type,fn):为DOM元素增加一个事件监听器 removeEvent(type,fn):移除先前为DOM元素添加的事件监听器 eg: var destroy = function ...
- 打开excel2007文档时显示“excel无法打开文件~$book.xltm”
此问题的出现是因为意外情况导致Excel临时文件没有删掉,把C:\Program Files\Microsoft Office\Office12\XLSTART里面的临时文件“~$book”给删除就好 ...
- PowerShell与Unix Shell对比:八大实例
PowerShell与Unix Shell对比:八大实例 本文将从八个实例对比PowerShell和Unix Shell,通常是Linux Bourne Shell(包括sh.ksh和bash等).二 ...
- 【MongoDB】学习MongoDB推荐三本书
近期学习mongodb,感觉这三本书写得不错.非常大家分享一下:
- c#indexof使用方法
IndexOf() 查找字串中指定字符或字串首次出现的位置,返首索引值,如: str1.IndexOf("字"): //查找"字"在str1中的索引值(位置) ...
- MongoDB -- 更新
$pull: db.collection.update( <query>, { $pull: { <arrayField>: <query2> } } ) $pul ...
- Java 反射机制[Method反射]
Java 反射机制[Method反射] 接着上一篇Java 反射机制[Field反射],通过调用Person类的setName方法将obj的name字段的Value设置为"callPerso ...
- Android 编程之第三方开发 MaoZhuaWeiBo微博开发演示样例-1
在大学期间我做过非常多类似这种APP.这个是我们小组之前做的,我后期增加非常多新元素.完好了这个应用,由于为了加强 专业技术嘛.也是常常熬夜写些小东西,嘿嘿.只是还算不错.起码技术长进了不少嘛,还是非 ...
- [C++]C++中的运行时类型检测
Date:2014-1-3 Summary: 使用C++中的运行时类型检测.(文章重点在于记录本人的使用情况,并非深层讨论RTTI) Contents:写习惯C#的我,在C++依然存在哪些.NET的惯 ...