WebSockets技術是用於雙向客戶端和伺服器之間通過Web進行通信的雙向全雙工協議。它已於2011年標準化,並與HTTP完全兼容。該協議支持實時應用,例如聊天,通知,實時供稿,多人遊戲和其他用例。
在本視頻中,我們將解釋什麼是WebSocket以及其發明的原因。然後,我們將使用WebSockets構建伺服器和客戶端。我們還將討論WebSockets的優缺點,並討論該技術的一些替代方案
視頻中的WebSockets源代碼
https://github.com/hnasr/javascript_playground/tree/master/websocket-demo
HTTP
*談論請求-響應顯示幻燈片。客戶一直在發起請求。想像一下構建一個聊天應用程序嗎?
Web套接字
-幻燈片顯示雙向全雙工標準網頁
—
WebSockets如何工作?
-WebSockets握手
-初始請求始終是HTTP,眾所周知,HTTP會創建一個tcp連接,然後該請求進行http升級,告訴伺服器將其用作雙向。
-一旦完成切換到二進位協議。
-Ws:// wss://協議
WebSocket用例
-聊天
-實時供稿
-多人遊戲
-進度欄/日誌記錄/上傳。
-WebSockets示例(伺服器/客戶端)
-WebServer的優缺點
優點
1.全雙工,無需持續輪詢
2.與HTTP兼容,因此代理知道如何處理
3.防火牆不會阻止它,它不會使用特殊埠
缺點
1.代理很棘手,許多代理和透明代理尚不支持
2.第7層負載平衡很棘手,負載平衡器超時。
3.實現起來比較複雜(簡單的telnet使用HTTP)
4.對於所有用例都不理想-(微服務)
-是否必須使用Web套接字? ( 備擇方案 )
重要的是要注意,WebSockets並不是唯一基於HTTP實時的解決方案,還有其他實現實時的方法,例如事件源和長時間輪詢。
-使用WebSocket進行負載平衡(獎金)
-第4層
-第7層(隧道)
長輪詢
事件源
Web套接字
資料來源:
https://developer.mozilla.org/zh-CN/docs/Web/API/WebSockets_API/Writing_WebSocket_servers
https://www.ably.io/concepts/websockets
https://link.medium.com/ljsSOsnW6Y
https://blog.stanko.io/do-you-really-need-websockets-343aed40aa9b
跳轉碼
HTTP 2:00
Web套接字5:40
WebSockets握手8:00
WebSockets用例11:20
14:30 WebSockets示例代碼
36:40 WebSockets的優缺點
42:10您必須使用webSockets嗎?
牌
2:40 HTTP速成班https://www.youtube.com/watch?v=0OrmKCB0UrQ
8:20 TLS https://www.youtube.com/watch?v=AlE5X1NlHgg
9:00什麼是Web伺服器https://www.youtube.com/watch?v=JhpUch6lWMw
39:40第4層與第7層負載平衡https://www.youtube.com/watch?v=aKMLgFVxZYk
Architecture軟體架構視頻
?資料庫工程視頻
?網路工程視頻
?負載平衡和代理視頻
?Postgres視頻
?程式設計影片
?網路安全視頻
?HTTP視頻
?Python視頻
?Javascript視頻
在PayPal上支持我https://bit.ly/33ENps4
成為贊助人https://www.patreon.com/join/hnasr嗎?
保持好狀況!
海珊。
Guys Jump codes for your convenience, HTTP 2:00 WebSockets 5:40 WebSockets Handshake 8:00 WebSockets Usecases 11:20 WebSockets Example Code 14:30 WebSockets Pros and Cons 36:40 Do you have to use webSockets? 42:10
Stay awesome!
7:14 …it's the wild west. very funny explanation. cool
dude, this could've been like 20 minute shorter without your antics.
thank you very much
i usually don't comment, but i have to give you the props for this amazing video. good job
Thanx Hussein
Say with me it's coolish ????? i loved the way you explain i enjoyed along with u thank you so much keep going ???
Hey could you please do a video about EventSource?
Everything you publish is so pro! thanks for making our lives easier to grasp!
I'm 11 minutes into this video and I love how professional this video is. Well done with the structuring! I can't believe this only has 4k views.
could you share your lounch.json file? I'm trying to follow your steps but it's not working
شكرا جزيلا على هذا الشرح
while connecting client and server m getting error on client side connection cannot be established
for me it's really difficult to watch such a long videos but your way of explaining things is so good that no one can resist it.Do make a video on EventSource.
I always like it when a channel has the perfect balance of comedy and education. Subscribed! Great stuff!
Thanks for this video, I found it really easy interesting, since I'm working on a web game right now.
I personally use this websocket server library: https://www.npmjs.com/package/ws
It doesn't require to create an http server which is pretty nice
who uses 1.0 anyway?
WEBrtc is also trending for a client to client video and audio chat. Will you please make a crash cource about it?
Thanks 🙂
excellent stuff mate. so glad I stumbled upon your channel.
assalamualaikum hussain sir
can you assist me on how to send message to a specific user using websocket
I cant believe i found this channel, this kinda of content is gold, please keep it up, also gonna watch that one about nodejs and webservers
THE FIRST 5 MINUTES INTO YOUR VIDEO MADE ME UNDERSTAND OVER 3 YEARS WORTH OF INFORMATION, U ARE A BLESSING Hussein Nasser
I HAVE NEVER KNOWN A GUY AS INTELLIGENT AT EXPLAINING STUFF LIKE Hussein Nasser, MUCH THANKS TO YOU SIR.
thank you for defining the levels of cool Hussein!
Can you make a Video how to make Bots for Online Games using Websockets? ?
Very nice.
Hussein in your book , you used the command line 『npm init』 to set up a web server. So, what is the difference between 『npm init』 and 『npm init -y』? Thank you.
Hussein I was wondering maybe if you can share your PPTs with us? I want to print them out and take notes on them ?
YES !!! I claim the first comment