1
I have studied the communication between two (or more) servers raised in Nodejs via REST
as I searched for content (references, explanations, benchmarks, etc.) I found indications of REST
would bring more cost to the process and WebSocket
would be more recommended however, all the material I found was related to client (front-end) to server(back-end).
The very succinct question is: how to connect and exchange messages between two servers via "sockets" (back-end only)?
The initial implementation I used REST
I worked with express to map routes and superagent to make requests.
Now when trying to use WebSocket
I’m using the module uws
example js
var WebSocketServer = require('uws').Server;
var wss = new WebSocketServer({ port: 3000 });
function onMessage(message) {
console.log('received: ' + message);
}
wss.on('connection', function(ws) {
ws.on('message', onMessage);
ws.send('something');
});