reading-notes

Code Fellows Notes

View the Project on GitHub stephnitis/reading-notes

Socket.io

Web Sockets

1. What is a Web Socket?

2. Describe the Web Socket request/response handshake and what happens once the connection is established.

The handshake starts with an HTTP request/response, allowing servers to handle HTTP connections as well as WebSocket connections on the same port. Once the connection is established, communication switches to a bidirectional binary protocol which does not conform to the HTTP protocol.

In addition to Upgrade headers, the client sends a Sec-WebSocket-Key header containing base64-encoded random bytes, and the server replies with a hash of the key in the Sec-WebSocket-Accept header. This is intended to prevent a caching proxy from re-sending a previous WebSocket conversation, and does not provide any authentication, privacy, or integrity. The hashing function appends the fixed string 258EAFA5-E914-47DA-95CA-C5AB0DC85B11 (a UUID) to the value from Sec-WebSocket-Key header (which is not decoded from base64), applies the SHA-1 hashing function, and encodes the result using base64

A universally unique identifier (UUID) is a 128-bit label used for information in computer systems

In cryptography, SHA-1 (Secure Hash Algorithm 1) is a cryptographically broken but still widely used hash function which takes an input and produces a 160-bit (20-byte) hash value known as a message digest

3. 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

1. What does the event handler io.on() do?

The io.on event handler handles connection, disconnection, etc., events in it, using the socket object.

2. Describe some possible proof of life or proof that the code works as expected

log “A user connected”, every time a user goes to this page and “A user disconnected”, every time someone navigates away/closes this page.

3. What does socket.emit() do?

You can create and fire custom events using the socket.emit function.

Socket.io vs Web Sockets

1. What is the difference between WebSocket and Socket.IO? (think Git and GitHub, or OAuth and Auth0).

WebSocket is the communication Protocol that provides bidirectional communication between the Client and the Server over a TCP connection; WebSocket remains open all the time, so they allow real-time data transfer. When clients trigger the request to the server, it does not close the connection on receiving the response; it rather persists and waits for the Client or server to terminate the request.

Socket.IO is a library that enables real-time and full-duplex communication between the Client and the Web servers. It uses the WebSocket protocol to provide the interface. Generally, it is divided into two parts; both WebSocket vs Socket.io are event-driven libraries.

2. When would you use Socket.IO?

3. When would you use WebSockets?

OSI Model Explained

What are a couple of key takeaways from this video?

Open system interconnection models

Package of protocols:

TCP Handshakes Explained

Translate the gist of this video to a non-technical friend

transmission control protocol, allows data to be delivered successfully and accurately. Uses a three way handshake to establish a connection. Step one the client sends request for connection, step two the server replies with an acknowledgment and asks client to also open a connection, lastly the client replies to confirm the connection.

Socket.io Documentation Socket.io Server API Socket.io Client API Socket Testing Tool