node.js - How can I have 2 Node apps on different servers that talk to each other? -


basically have middle-man webpage website people can go to, login , create servers (for game) in different locations, e.g. texas, new york, chicago.

right have main app running on new york

i want have sub-app runs on servers solely responsible creating child_processes start servers.

i playing around having sub-apps run off of get/post requests, trying send get/post requests node side painful, , trying secure other people don't curl request , malicious there way maybe sockets or sub-apps connect main socket of main web-app , can send out start emit or sub-apps create server? sorry if doesn't make sense i'm new having apps talk each other.

you can make 2 node servers communicate websocket node module 'ws'. can install typing command:

npm install --save ws 

to connect node apps, 1 node app should listening on port (for exapmle: 3001), make acting server other node app :

var websocketserver = require('ws').server, wss = new websocketserver ({port: 3001, path: '/path'}); wss.on('listening', function() {     console.info('ws server listening') }) 

and can connect other node app this:

var websocket = require('ws'); var ws  = new websocket('ws://www.yourserverdomain.com:3001/path'); 

now can send , receive data both sides, can see in link see how it.


Comments