日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > asp.net >内容正文

asp.net

ASP.NET Web实时消息后台服务器推送技术---GoEasy

發(fā)布時間:2023/12/31 asp.net 45 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ASP.NET Web实时消息后台服务器推送技术---GoEasy 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

越來越多的項目需要用到實時消息的推送與接收,怎樣用ASP.NET實現(xiàn)最方便呢?我這里推薦大家使用GoEasy, 它是一款第三方推送服務(wù)平臺,使用它的API可以輕松搞定實時推送!

瀏覽器兼容性:GoEasy推送 支持websocket 和polling兩種連接方式,從而可以支持IE6及其以上的所有版本,同時還支持其它瀏覽器諸如Firefox, Chrome, Safari等等。

支持不同的開發(fā)語言:??? GoEasy推送 提供了Restful API接口,無論你的后臺程序用的是哪種語言都可以通過Restful API來實現(xiàn)后臺實時推送。如:Java,PHP, C#, Ruby, Python, C, C++, ASP.NET,Node.js...

支持后臺及前臺推送: 后臺用Restful API, 前臺用goeasy.js; 運用十分簡單!

?

ASP.NET Web實時消息后臺服務(wù)器推送技術(shù)-GoEasy

?

下面我介紹一下使用GoEasy的步驟:

?

1. 你需要到goeasy官網(wǎng)上注冊一個賬號,并創(chuàng)建一個應(yīng)用,應(yīng)用創(chuàng)建好后系統(tǒng)會默認(rèn)為它生成兩個key: publish key和subscribe key

?

2. 前臺實時訂閱及接收

??? 只需要引入goeasy.js,然后調(diào)用goeasy的subscribe方法訂閱一個channel即可,訂閱時無論是用publish key還是subscribe key都可以。通過subscribe的參數(shù) onMessage的回調(diào)函數(shù)可以實時接收到消息。

?

3. 前臺實時推送

??? 還是需要引入goeasy.js(如果該頁面已經(jīng)引入了可不在引入),然后調(diào)用goeasy的publish方法向已訂閱的channel上推送消息即可,推送時只能用publish key。

?

4. 后臺實時推送

???? 調(diào)用GoEasy Restful API, 用post方式訪問http://goeasy.io/goeasy/publish, 同時還需要帶上三個必要參數(shù):

??? appkey: publish key

??? channel: 你訂閱了的channel

?? content: 推送內(nèi)容

?

就是這么簡單。

下面我將之前寫的一個小實例貼出來,里面用了Javascript 在web頁面進(jìn)行訂閱,推送,接收,以及取消訂閱的例子,里面的appkey用的是goeasy官方的demo 的appkey.

<html> <head> <title>GoEasy Test</title> <script type="text/javascript" src="https://cdn.goeasy.io/goeasy.js"></script> <script type="text/javascript"> if(typeof GoEasy !== 'undefined'){ var goEasy = new GoEasy({ appkey: 'ba821151-e043-4dfb-a954-c73744c8d323', userId:"222", username:"22", onConnected:function(){ console.log("Connect to GoEasy success."); } , onDisconnected:function(){ console.log("Disconnect to GoEasy server."); } , onConnectFailed:function(error){ console.log("Connect to GoEasy failed, error code: "+ error.code+" Error message: "+ error.content); } }); } subscribe(); function subscribe(){ goEasy.subscribe({ channel: 'notification', onMessage: function(message){ console.log('Meessage received:'+message.content); }, onSuccess:function(){ console.log("Subscribe the Channel successfully."); }, onFailed: function(error){ console.log("Subscribe the Channel failed, error code: "+ error.code + " error message: "+ error.content); } }); } function publishMessage(){ goEasy.publish({ channel: 'notification', message: 'You received a new notification', onSuccess:function(){ console.log("Publish message success."); }, onFailed: function(error){ console.log("Publish message failed, error code: "+ error.code +" Error message: "+ error.content); } }); } function unsubscribe(){ goEasy.unsubscribe({ channel:"notification", onSuccess: function(){ console.log("Cancel Subscription successfully."); }, onFailed: function(error){ console.log("Cancel the subscrition failed, error code: "+ error.code + "error message: "+ error.content); } }); } </script> </head> <body> <input type="button" value="publish" onclick="publishMessage()"/> <input type="button" value="unsubscribe" onclick="unsubscribe()"/> <input type="button" value="subscribe" onclick="subscribe()"/> </body> </html>

?

轉(zhuǎn)載于:https://www.cnblogs.com/EmmaGong/p/6022988.html

總結(jié)

以上是生活随笔為你收集整理的ASP.NET Web实时消息后台服务器推送技术---GoEasy的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。