diff --git a/test-rpc-server/rpc-message.js b/test-rpc-server/rpc-message.js index c0b1405..6b9b21e 100644 --- a/test-rpc-server/rpc-message.js +++ b/test-rpc-server/rpc-message.js @@ -18,6 +18,8 @@ module.exports = class RpcMessage { try { return JSON.parse(msg); } catch(e) { + console.log(`failed to parse "${msg}"`); + console.error(e); return {}; } } diff --git a/test-rpc-server/rpc-server.js b/test-rpc-server/rpc-server.js index 83f3362..7f1e72e 100644 --- a/test-rpc-server/rpc-server.js +++ b/test-rpc-server/rpc-server.js @@ -1,8 +1,6 @@ const net = require('net'); const RpcMessage = require('./rpc-message'); -console.log('Start up'); - let PipePrefix; let PipePostfix; if (process.platform == 'win32') { @@ -13,25 +11,27 @@ else { PipePrefix = "/tmp"; PipePostfix = '.pipe'; } +const PipePath = PipePrefix + 'DiscordRpcServer' + PipePostfix; +let connections = 0; -const PipePath = PipePrefix + "DiscordRpcServer" + PipePostfix; +const server = net.createServer(function(sock) { + connections += 1; + console.log('Server: on connection', connections); + let myConnection = connections; -var server = net.createServer(function(stream) { - console.log('Server: on connection'); - - stream.on('data', function(data) { + sock.on('data', function(data) { const msgObj = RpcMessage.deserialize(data); if (msgObj != null) { - console.log('Server: on data:', msgObj); + console.log('Server: on data:', myConnection, msgObj); } else { - console.log('Server: got some data'); + console.log('Server: got some data', data.toString()); } }); - - stream.on('end', function() { - console.log('Server: on end') - server.close(); + + sock.on('end', function() { + connections -= 1; + console.log('Server: on end', connections); }); }); @@ -45,4 +45,4 @@ try { }); } catch(e) { console.error('could not start server:', e); -} \ No newline at end of file +}