Any web socket instance has by default the namespace disconnect- which emits a message back to the server if the instance has disconnected from the frontend (usually due to disconnection from its web server)ģ. The library socket.io is imported via: const socketio=require("socket.io")Ģ. So there are a few crucial points that should be noted in the above code snippet:ġ. After installing the NodeJS Socket.io library via npm install socket.io, the server-side code implementation is as follows: the entry point of the web application where an instance of Express.js is being initialised. Server-Side Implementation of Socket.ioįor starters, within an Express NodeJS web app, the server-side of the code conventionally refers to the app.js/server.js file i.e. While there are alternative libraries which are capable of integrating real-time data streaming within a web app, my primary reason for implementing Socket.io is because it not only serves its functionality of establishing a Web socket bidirectional connection between Server + Client but also, both Server & Client code implementations are written in JavaScript so there is no need to switch back and forth between 2 languages while coding the application’s backend and frontend. In short, I was curious about what other data fields the API includes in its real-time responses □ I later decided to further explore and leverage on the data provider’s public API which includes returning the real-time bus arrival timings at any specific bus stop. Screenshot by Author | The Origin-Destination bus route data selected can be exported on the web app
0 Comments
Leave a Reply. |