Test server: print more diagnostics, track connections more
This commit is contained in:
parent
568de58f36
commit
d14e810be0
2 changed files with 16 additions and 14 deletions
|
@ -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 {};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue