NetCore.SignalR.Demo演示

項目github,點擊https://github.com/wangpengzong/NetCore.SignalR.Demogit

 

1.打開服務端Server(\SignalR.Server\bin\Debug\netcoreapp2.2\win10-x64\SignalR.Server.exe)github

 

2.打開客戶端,開5個標籤頁,分別是app

兩個http://localhost:63891/test/index     groupid:1,用戶1,identifier = "00000000-0000-0000-0000-000000000000"ide

一個http://localhost:63891/test/index1   groupid:1,用戶2,identifier = "11111111-1111-1111-1111-111111111111"spa

一個http://localhost:63891/test/index2   groupid:2,用戶3,identifier = "33333333-3333-3333-3333-333333333333".net

一個http://localhost:63891/test/index3   groupid:3,用戶4,identifier = "44444444-4444-4444-4444-444444444444"blog

 

 

Javascript調用:ip

test/index中的user框,輸入00000000-0000-0000-0000-000000000000message輸入hi,點擊sendmessage,就能夠在所有的標籤頁看到以上頁面,此時調用的是get

document.getElementById("sendButton").addEventListener("click", event => {it

            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

 

相關文章
相關標籤/搜索