What is a Web Socket?
A Web Socket is a communication protocol that provides full-duplex communication channels over a single TCP connection. It allows real-time data exchange between a server and a client.
Describe the Web Socket request/response handshake and what happens once the connection is established.
The Web Socket handshake begins with a standard HTTP request from the client to the server. If the server supports Web Sockets, it returns an HTTP 101 Switching Protocols response. Once the connection is established, data can be sent back and forth between client and server in real time.
Web Sockets provide a standardized way for the server to send content to a client without first receiving a ____ from that client.
request
What does the event handler io.on()
do?
The
io.on()
event handler listens for specific events emitted by the server or client in Socket.io. When the specified event occurs, it executes a callback function.
Describe some possible proof of life or proof that the code works as expected
You can use console.logs or test events to verify the code works. For example, you can have the server emit a message when a new connection is established and check the console for the message.
What does socket.emit() do?
The
socket.emit()
function sends a message to the server or client associated with the socket. For example,socket.emit('message', 'Hello World');
would send the message “Hello World” to the server or client.
What is the difference between WebSocket and Socket.IO? (think Git and GitHub, or OAuth and Auth0).
WebSockets is a communication protocol, whereas Socket.IO is a library that uses WebSockets under the hood but also provides additional features like broadcasting and namespaces.
When would you use Socket.IO?
You would use Socket.IO when you need real-time functionality in your application, like chat apps, real-time analytics, or multiplayer games, and you want to take advantage of its additional features like automatic reconnection and event broadcasting.
When would you use WebSockets?
You would use WebSockets when you need a simple, real-time, two-way communication between the client and server in your web application and you don’t require the additional features provided by Socket.IO.
What are a couple of key takeaways from this video?
The OSI Model is a conceptual framework used to understand how different network protocols interact and work together to provide network services. The model is divided into seven layers, each representing a specific network function.
Translate the gist of this video to a non-technical friend
The video explains the process of how computers establish a connection to exchange data. It compares it to a phone call, where you dial a number (SYN), the other party picks up (SYN-ACK), and then you start talking (ACK).