-
// We'll be using the https://github.com/theturtle32/WebSocket-Node // WebSocket implementation var WebSocketServer = require('websocket').server; var http = require('http'); var server = http.createServer(function(request, response) { // process HTTP request. }); server.listen(1337, function() { }); // create the server wsServer = new WebSocketServer({ httpServer: server }); // WebSocket server wsServer.on('request', function(request) { var connection = request.accept(null, request.origin); // This is the most important callback for us, we'll handle // all messages from users here. connection.on('message', function(message) { // Process WebSocket message }); connection.on('close', function(connection) { // Connection closes }); });
-
InfluxDB
InfluxDB – Built for High-Performance Time Series Workloads. InfluxDB 3 OSS is now GA. Transform, enrich, and act on time series data directly in the database. Automate critical tasks and eliminate the need to move data externally. Download now.
-
This is where Server-Sent Events (SSE) become very useful. SSE is a mechanism that allows the server to asynchronously push the data to the client once the client-server connection is established. The server can then decide to send data whenever a new "chunk" of data is available. It can be considered as a one-way publish-subscribe model. It also offers a standard JavaScript client API named EventSource implemented in most modern browsers as part of the HTML5 standard by W3C. Note that browsers that do not support EventSource API can be easily polyfilled.
-
GET ws://websocket.example.com/ HTTP/1.1 Origin: http://example.com Connection: Upgrade Host: websocket.example.com Upgrade: websocket