NetCore.SignalR.Demo演示
项目github,点击https://github.com/wangpengzong/netcore.signalr.demo
1.打开服务端server(\signalr.server\bin\debug\netcoreapp2.2\win10-x64\signalr.server.exe)
2.打开客户端,开5个标签页,分别是
两个http://localhost:63891/test/index groupid:1,用户1,identifier = "00000000-0000-0000-0000-000000000000"
一个http://localhost:63891/test/index1 groupid:1,用户2,identifier = "11111111-1111-1111-1111-111111111111"
一个http://localhost:63891/test/index2 groupid:2,用户3,identifier = "33333333-3333-3333-3333-333333333333"
一个http://localhost:63891/test/index3 groupid:3,用户4,identifier = "44444444-4444-4444-4444-444444444444"
javascript调用:
在test/index种user,输入00000000-0000-0000-0000-000000000000,message输入hi,点击sendmessage,就可以在全部的标签页看到以上页面,此时调用的是
document.getelementbyid("sendbutton").addeventlistener("click", event => {
const user = document.getelementbyid("userinput").value;
const message = document.getelementbyid("messageinput").value;
connection.invoke("sendmessagetoall", { from: user, content: message }).catch(err => console.error(err.tostring()));
event.preventdefault();
});
.net 客户端调用
再打开一个标签页,输入http://localhost:63891/test/sendmessagetoall
这个和上面的say hi都是调用sendmessagetoall方法,发送给所有人
将此标签页输入http://localhost:63891/test/sendmessagetouser,调用sendmessagetouser方法,此时前两个页面显示00000000-0000-0000-0000-000000000000 says sendmessageto1,这个是发给用户1
将此标签页输入http://localhost:63891/test/sendmessagetogroup1,调用sendmessagetomygroup方法,此时前三个页面显示00000000-0000-0000-0000-000000000000 says sendmessagetogroup1,这个是发给组1
将此标签页输入http://localhost:63891/test/sendmessagetogroup1and2,调用sendmessagetomygroup方法,此时前四个页面显示00000000-0000-0000-0000-000000000000 says sendmessagetogroup1,这个是发给组1和组2