Websocket is not much to say here, Xiao Zhazha has a post that has been introduced before, if you don't understand, you can Baidu or go to this post to see (.net/c# simulate websocket client connection [source code]
https://www.itsvse.com/thread-3652-1-1.html)。 Okay, not much to say, before the web message notification, I saw a lot of people using ajax rotation training to check, it was a bit of a waste of resources, and there were also long connections to do, I used WebSocket+iNotify.js. iNotify.js is an encapsulated web message notification, which uses the Notification() API interface, which can pop up in the lower right corner when your website is minimized, which is very useful. However, after version 62 in Google Chrome, the website needs to be https, which will be mentioned later. It also uses a websocket heartbeat, which will ask the server for the data you need at a set time. Okay, so much nonsense, post the code below, and attach it to the source code. Client: heartBeat.js
Server:
ps: If you download the source code, it is best to deploy the web page to the local IIS to test, otherwise the pop-up window will not pop up, if you use it in the official project, you should pay attention to the Google Chrome restriction website mentioned earlier must be an HTTPS pop-up window will pop up, Then if you want to implement the frontend on the Https site, use wss (var wsUrl = 'wss://127.0.0.1:4649'; The server side also needs to change the code accordingly, and it needs to be processed with the Https protocol, which I am still researching.
However, Firefox can be tested by other browsers in 360 speed mode. If anyone has studied WSS, they can share it, study it, thank you.
Source code download:
Tourists, if you want to see the hidden content of this post, please Reply |