Reading: Socket.io
Review, Research, and Discussion
- What is the benefit of transforming data into packets?
- Packets are the basic units of communication over a TCP/IP network. Devices on a TCP/IP network divide data into small pieces, allowing the network to accommodate various bandwidths, to allow for multiple routes to a destination, and to retransmit the pieces of data which are interrupted or lost.
-
For further information clicks =>here
- UDP is often refereed to as a connection less protocol. Why is this?
- UDP is a connection less protocol. It is known as a datagram protocol because it is analogous to sending a letter where you don’t acknowledge receipt.
-
For further information clicks =>here
- Can a socket server application have multiple socket connections?
- A server socket listens on a single port. All established client connections on that server are associated with that same listening port on the server side of the connection. An established connection is uniquely identified by the combination of client-side and server-side IP/Port pairs. Multiple connections on the same server can share the same server-side IP/Port pair as long as they are associated with different client-side IP/Port pairs, and the server would be able to handle as many clients as available system resources allow it to.
-
For further information clicks =>here
- Can you make a client socket and a server socket in one?
- Yes and no. It isn’t very clear what you’re trying, though. So the answer isn’t very clear either.
- However, if you want to use a client socket and a server socket within a single application, then yes! You can do that if you’re willing to use two different ports. Or if the sockets won’t be using the same port at the same time.
- The first would be simple and a generic POP3/SMTP application is a great example for this. The SMTP client socket would be on port 25, sending emails whenever requested by the user. The POP3 server socket listens to port 110 for any incoming emails. This way, you have two sockets within the same application, which even could be used to communicate with one another. (Not very practical, but it can be done.)
- The other option is to open port X for the server connection and listen for any commands. Once a command is provided, you close the server socket and open a new client socket on port X to send data to somewhere else. Once data is sent, you can close the client socket and open the server socket again. This approach would block the server for as long as you would be using the client socket and visa versa. It isn’t very practical, though.
-
For further information clicks =>here
- Yes and no. It isn’t very clear what you’re trying, though. So the answer isn’t very clear either.
Vocabulary
- Observer Pattern
- The observer pattern is a software design pattern in which an object, named the subject, maintains a list of its dependents, called observers, and notifies them automatically of any state changes, usually by calling one of their methods.
-
For further information clicks =>here
- Listener
- An event listener is a procedure in JavaScript that waits for an event to occur. The simple example of an event is a user clicking the mouse or pressing a key on the keyboard.
-
For further information clicks =>here
- Event Handler
- You can define Event handlers, scripts that are automatically executed when an event occurs. Event handlers are embedded in documents as attributes of HTML tags to which you assign JavaScript code to execute.
-
For further information clicks =>here
- Event Driven Programming
- Event-driven programming is when a program is designed to respond to user engagement in various forms. It is known as a programming paradigm in which the flow of program execution is determined by “events.” Events are any user interaction, such as a click or key press, in response to prompt from the system.
-
For further information clicks =>here
- Event Loop
- The event loop continuously checks the call stack to see if there’s any function that needs to run. While doing so, it adds any function call it finds to the call stack and executes each one in order.
-
For further information clicks =>here
- Event Queue
- The event queue is responsible for sending new functions to the track for processing. It follows the queue data structure to maintain the correct sequence in which all operations should be sent for execution. Whenever an async function is called, it is sent to a browser API. These are APIs built into the browser.
-
For further information clicks =>here
- Call Stack
- A call stack is a mechanism for an interpreter (like the JavaScript interpreter in a web browser) to keep track of its place in a script that calls multiple functions — what function is currently being run and what functions are called from within that function, etc.
-
For further information clicks =>here
- Emit
- Emit’s job is to trigger named event(s) which in turn cause functions called listeners to be called.
-
For further information clicks =>here
- Database
- A database is an organized collection of structured information, or data, typically stored electronically in a computer system. A database is usually controlled by a database management system (DBMS). Together, the data and the DBMS, along with the applications that are associated with them, are referred to as a database system, often shortened to just database.
-
For further information clicks =>here
Preparation
- WebSocket
- WebSocket is a computer communications protocol, providing full-duplex communication channels over a single TCP connection. The WebSocket protocol was standardized by the IETF as RFC 6455 in 2011, and the WebSocket API in Web IDL is being standardized by the W3C.
- The WebSocket protocol enables interaction between a web browser (or other client application) and a web server with lower overhead than half-duplex alternatives such as HTTP polling, facilitating real-time data transfer from and to the server. This is made possible by providing a standardized way for the server to send content to the client without being first requested by the client, and allowing messages to be passed back and forth while keeping the connection open. In this way, a two-way ongoing conversation can take place between the client and the server. The communications are usually done over TCP port number 443 (or 80 in the case of unsecured connections), which is beneficial for environments that block non-web Internet connections using a firewall. Similar two-way browser-server communications have been achieved in non-standardized ways using stopgap technologies such as Comet.
- Socket.IO
- Socket.IO enables real-time bidirectional event-based communication. It works on every platform, browser or device, focusing equally on reliability and speed. Socket.IO is built on top of the WebSockets API (Client side) and Node.js. It is one of the most depended upon library on npm (Node Package Manager).
- Socket.IO is a JavaScript library for real-time web applications. It enables real-time, bi-directional communication between web clients and servers. It has two parts: a client-side library that runs in the browser, and a server-side library for node.js. Both components have an identical API.
- Writing a real-time application with popular web applications stacks like LAMP (PHP) has traditionally been very hard. It involves polling the server for changes, keeping track of timestamps, and it is a lot slower than it should be.
- Sockets have traditionally been the solution around which most real-time systems are architected, providing a bi-directional communication channel between a client and a server. This means that the server can push messages to clients. Whenever an event occurs, the idea is that the server will get it and push it to the concerned connected clients.
- Socket.IO is quite popular, it is used by Microsoft Office, Yammer, Zendesk, Trello, and numerous other organizations to build robust real-time systems. It one of the most powerful JavaScript frameworks on GitHub, and most depended-upon NPM (Node Package Manager) module. Socket.IO also has a huge community, which means finding help is quite easy.
-