Socket.io
Web Sockets
What is a Web Socket? WebSocket is a computer communications protocol, providing full-duplex communication channels over a single TCP connection.
Describe the Web Socket request/response handshake and what happens once the connection is established. WebSocket “is designed to work over HTTP ports 443 and 80 as well as to support HTTP proxies and intermediaries”, thus making it compatible with HTTP. To achieve compatibility, the WebSocket handshake uses the HTTP Upgrade header[3] to change from the HTTP protocol to the WebSocket protocol.
Web Sockets provide a standardized way for the server to send content to a client without first receiving a ____ from that client. request
Socket.io Tutorial
What does the event handler io.on() do? Whenever an event occurs, the server will get it and push it to the concerned connected clients.
Describe some possible proof of life or proof that the code works as expected: It logs “A user connected”, every time a user goes to this page and “A user disconnected”, every time someone navigates away/closes this page.
What does socket.emit() do? It will send a message to all connected clients.
Socket.io vs Web Sockets
What is the difference between WebSocket and Socket.IO? (think Git and GitHub, or OAuth and Auth0). WebSocket is the technology, while Socket.io is a library for WebSockets. Websocket provides the Connection over TCP, while Socket.io is a library to abstract the WebSocket connections.
When would you use Socket.IO?
- When you built real time applications, like Group chat Room, video conferencing, multiplayer games etc.
- If you want server to push data by itself without calling from client.
When would you use WebSockets? When a client needs to react quickly to a change (especially one it cannot predict), a WebSocket may be best. Consider a chat application that allows multiple users to chat in real-time. If WebSockets are used, each user can both send and receive messages in real-time.
Videos
OSI Model Explained
- It’s a standard model for network communications
- It uses the TCP/IP model
- It is made of seven layers:
- Application Layer - Human-computer interaction layer thwre application can access network services
- Presentation Layer - Ensures that data is useable. This is where encryption occurs
- Session Layer - Maintains conenctions and is responsible for controlling ports and sessions
- Transport Layer - Transmits data using transmission protocols including TCP and UDP
- Network Layer - Decides which physical path the data will take
- Data Link Layer - Defines the format of data on the network
- Physical Layer: Transmits raw bit stream over the physical medium
TCP Handshakes Explained
Transmission Control Protocol that uses a three-way handshake
- The client send a SYN segment to the server, asking for a connection (client sends a Seq# and ACK of 0)
- The server replies with SYN-ACK, meaning synchronization and acknowedgement. It asks the cliet to open a connnection (server replies with an ACK of the clients Seq# + 1, and its own Seq#)
- The client agree and they are connected. (client replies with an ACK of the server’s Seq# + 1, and a SYN# of 0 )