Class Twelve Notes (401)
Socket.io
Web Sockets
- Web Socket: a computer communations protocol, Web Sockets are the current API specification that allows web apps to use the protocol;
- Web Sockets provide a standardized way for the server to send content to a client without first receiving a request from that client.
- Once request/response handshake and once the connection is established after an HTTP connection, the communication switches to a bi-directional binary protocol.
Socket Tutorial
- The event handler
io.on()
on the server side handles events emitted from the client side
- “Proof of life” can be verified by console log the message from the client using a custom event;
socket.emit()
emits an event from the client’s browser to the server
Socket.io vs Web Sockets
- Web Sockets is the communication protocol that allows the client and the server to communcation over a TCP connection. Socket.io is an API that allows developers to use the WebSocket protocol. On the client-side, it is the library that runs inside the browser, and on the server side, it’s the library for Node.js
- Websockets are used when the developer is trying to let its client and browser communicate over the TCP connection with minimal latency
- Socket.io is used when there’s multiple sockets at a time needs to be handled at once and transparancy is needed, also it allows the client to communicate with the server, and it upgrades the requirement to WebSockets when needed.
OSI and TCP Models Explained
- OSI model allows computers with different OS to connect to each other over the internet with multiple layers
- application layer: broswer, example include file transfer, web surfing, emails, and virtual terminals
- Presentation layer: data received from application to presentation. The two layers communicate using binaryr with translation and data compression, then encryption/decryption
- The following layer is session layer that provides APIs, which performs authentication/authorizations, and this layer keeps track of what data packets are being transferred (session management)
- Transport layer: data is segmented into smaller chunks of data. This layer performs flow and error control. This layer provides two services including connectionon-oriented transmission and connecionless transmission, floowing TCP and UDP.
- Network layer which transfers data packets between computers in different networks, it identifies which data to send to whom using their unique IP addresses
- Data Link Layer: using MAC address to identify the machine, it’s the physical link between the two computers
- Physical Layer
- TCP handshake: The client must first SYN request asking the server to oepn a request, then the server ackowledge the request via SYN-ACK, and ask the client to open a connection. Then client sends over ACK request to est. a two-way handshake, which then ACK is set to 0.
- When SYN request is ackowledged, the SYN-ACK request adds 1 to the port number
Back to main page
References