Переглядів 271,655
WebSockets technology is a bidirectional, full-duplex protocol for communication between client and server over the web. It has been standardized in 2011 and its fully compatible with HTTP. This protocol enables realtime applications such as chatting, notifications, live feed , multiplayer gaming and otheruse cases.
In this video we will explain what WebSockets are and why it was invented. we will then build a server and client using WebSockets. We will also talk about the pros and cons of WebSockets, and discuss some alternatives to this technology
Chapters
0:00 Intro
2:00 HTTP
5:40 WebSockets
8:00 WebSockets Handshake
11:20 WebSockets Usecases
14:30 WebSockets Example Code
36:40 WebSockets Pros and Cons
42:10 Do you have to use webSockets?
Source Code in the video for WebSockets
github.com/hnasr/javascript_p...
HTTP
* talk about request-response show a slide. Client initiate request all the time. Imagine building a chatting app?
WebSockets
- Slide showing bidrectional full duplex standard web
-
How WebSockets Work?
- WebSockets handshake
- Initial request is always HTTP which we all know creates a tcp connection, that request then http upgrade tells the server to use it as bidirectional.
- Once done switches to binary protocol.
- Ws:// wss:// protocol
WebSocket use cases
- Chatting
- Live feeds
- Multiplayer gaming
- Progress bar/ logging/ uploading..
- WebSockets example (Server/Client)
- WebServers Pros and Cons
Pros
1. Full-duplex no need for constant polling
2. compatible with HTTP, so proxies know to deal with it
3. Firewalls won’t block it doesn’t use a special port
Cons
1. Proxying is tricky, lots of proxies and transparent proxies don’t support it yet
2. Layer 7 load balancing is tricky, timeouts on the load balancer.
3. More complicated to implement (simple telnet use HTTP)
4. Not ideal for all use cases - (microservices)
- Do you have to use Web Sockets ? ( alternatives )
It is important to note that WebSockets is not the only HTTP realtime based solution, there are other ways to achieve real time such as eventsource, and long polling.
- Load Balancing with WebSockets (bonus)
- layer 4
- Layer 7 (tunnel)
Longpolling
Eventsource
WebSockets
Sources:
developer.mozilla.org/en-US/d...
www.ably.io/concepts/websockets
/ ljssosnw6y
blog.stanko.io/do-you-really-...
Cards
HTTP Crash Course • Hyper Text Transfer Pr...
TLS • Transport Layer Securi...
What is a Web Servers • What are web servers a...
Layer 4 vs Layer 7 Load Balancing • Load balancing in Laye...
Support my work on PayPal
bit.ly/33ENps4
Become a Member on UKposts
/ @hnasr
🧑🏫 Courses I Teach
husseinnasser.com/courses
🏭 Backend Engineering Videos in Order
backend.husseinnasser.com
💾 Database Engineering Videos
• Database Engineering
🎙️Listen to the Backend Engineering Podcast
husseinnasser.com/podcast
Gears and tools used on the Channel (affiliates)
🖼️ Slides and Thumbnail Design
Canva
partner.canva.com/c/2766475/6...
🎙️ Mic Gear
Shure SM7B Cardioid Dynamic Microphone
amzn.to/3o1NiBi
Cloudlifter
amzn.to/2RAeyLo
XLR cables
amzn.to/3tvMJRu
Focusrite Audio Interface
amzn.to/3f2vjGY
📷 Camera Gear
Canon M50 Mark II
amzn.to/3o2ed0c
Micro HDMI to HDMI
amzn.to/3uwCxK3
Video capture card
amzn.to/3f34pyD
AC Wall for constant power
amzn.to/3eueoxP
Stay Awesome,
Hussein