使用Websocket控制數據流-JavaScript編程系列



從2011年開始,創建了新的TCP通信,以允許從客戶端到伺服器的雙向數據。自從首次引入以來,websocket已經在現代瀏覽器中得到了很好的支持,在生產系統中也越來越普遍。

在本教程中,我們將介紹websocket的客戶端和伺服器實現,以創建功能齊全的通信渠道。

W3C規範:https://www.w3.org/TR/2011/WD-websockets-20110929/

通過「我可以使用」獲得瀏覽器支持:http://caniuse.com/websockets/embed/

Websocket上的MDN文檔:https://developer.mozilla.org/en-US/docs/Web/API/WebSocket

Github回購代碼:https://github.com/ignoreintuition/websocket

3 comments
  1. If you have several distinct functionalities on your frontend like a video player and a real-time chat, how do you differentiate the messages coming from the backend to route the data to the correct component? In this case, do you create multiple sockets i.e. one per component?

Comments are closed.