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-000000000000message输入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

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM