Code 401: Class 12 - Socket.io
Questions
-
What is the benefit of transforming data into packets? Splitting the data allows each piece to be sent independent of the others and reassembled on the receiving end which allows for more network flexibility.
-
UDP is often refereed to as a connections protocol. Why? UDP does not require a server and client to establish a three-way handshake prior to transmission.
-
Can a socket server application have multiple socket connections? Yes, using socket.io
-
Can a socket connection application be connected to multiple socket servers? Yes, as long as each connection is associated with a different client IP/Port.
-
Can an application be both a socket server and a socket connection? Not if they are intended to be used at the same time on the same port.
Vocabulary
Observer Pattern Software design pattern where an object notifies its dependents automatically of any state changes
Listener An object or function that is activated by a specific event
Event Handler Function that responds or processes an event
Event Driven Programming Programming in which the flow of the processes are determined by events such as user input
Event Loop Programming construct that waits for and dispatches events
Event Queue Where events are stored prior to execution
Call Stack Where functions are stored prior to execution
Emit/Raise/Trigger Methods for triggering an event
Subscribe Similar to .then()
Database Data storage structure
- Open System Integration Model (OSI Model)
- Application layer Used by network applications, use HTTP or HTTPS, FTP, SMTP, Telnet
- presentation layer Receives data from application layer, in terms of numbers and letters and translates to binary. Data compression occurs here, encryption also occurs here, SSL (Secure Socket Layer)
- Session layer Sets up and manages connections, API’s, NETBIOS, Authentication occurs here, Authorization occurs here, data transferred via data packets
- Transport layer Segmentation - splits data into smaller segments, Flow Control - controls amount of data transfer speed, Error control, checksum used to check for corruption, TCP, UDP
- Network layer Sends packets via logical addressing, ip addressing, routing, path determination, OSPF
- Data Link layer Access the media via Framing, controls how data is placed for media, LAN Cable, Optical Fiber, Wifi
- Physical layer
- TCP Transmission Control Protocol
- SYN segment set to server
- Server replies with SYN-ACK
- Client replies with ACK
- Two connection is established
- WebSocket communications protocol over single TCP
- Socket.io enables real-time bidirectional event-based communication, built on top of web sockets API and node.js
- This site offers a tutorial to help users build “moderately complex real-time websites, back-ends for mobile applications, and push notifications”
- Socket.io is a JS library for real-time web apps
$npm i socket.io
to install in a directory
- WebSocket remains open all of the time to allow for realtime transfer, event driven
- Socket.io is a library that allows for full duplex communication, event driven
- WebSocket protocol schema
ws://example.com:4000/chatroom.php
ws://
Schema
example.com
Host
:4000
Port
/chatroom.php
Server
- Socket.io allows for broadcasting multiple sockets at the same time
Return to reading-notes Deployed Site
Return to reading-notes Mark Down