Created
July 9, 2020 08:40
-
-
Save clockworkgr/d3a3f6005f1793ecc7474b62d5fd62da to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const WebSocket = require('ws'); | |
const wss = new WebSocket.Server({ port: 8090 }); | |
var front=[]; | |
var back=[]; | |
var conn_id=0; | |
var incount=[]; | |
var backcount=[]; | |
var calls={}; | |
wss.on('connection', async function connection(ws) { | |
//console.log('Incoming ws') | |
ws.conn_id=conn_id; | |
front[conn_id]=ws; | |
incount[conn_id]=0; | |
//console.log('Incoming ws stored') | |
let backend= connect(conn_id); | |
conn_id++; | |
ws.on('message', async function incoming(message) { | |
await backend; | |
//console.log('Incoming msg front') | |
msg=JSON.parse(message); | |
if (calls[msg.params[1]]===undefined) { | |
calls[msg.params[1]]=1; | |
}else{ | |
calls[msg.params[1]]++; | |
} | |
if (msg.params[1]=='get_account_history') { | |
console.log(msg.params[2][0]); | |
} | |
if (msg.params[1]=='get_objects') { | |
console.log(message); | |
} | |
back[this.conn_id].send(message); | |
incount[this.conn_id]++; | |
}); | |
}); | |
async function connect(conn_id) { | |
//console.log('Conecting to back'); | |
return new Promise(function(resolve, reject) { | |
back[conn_id] = new WebSocket('ws://127.0.0.1:8092'); | |
backcount[conn_id]=0; | |
back[conn_id].on('open', function open() { | |
//console.log('Connected to Back') | |
resolve(); | |
}); | |
back[conn_id].on('message',function incoming(message) { | |
//console.log('Incoming message from back') | |
//console.log(message); | |
backcount[conn_id]++; | |
front[conn_id].send(message); | |
}); | |
}); | |
} | |
function intervalFunc() { | |
console.log("RPC Calls made: "+incount); | |
console.log("API Node Responses and Subscription pushes: "+backcount); | |
console.log(calls); | |
} | |
setInterval(intervalFunc, 10000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment