mirror of
https://github.com/yuzu-emu/discord-rpc.git
synced 2024-12-22 19:15:32 +00:00
Test server: print more diagnostics, track connections more
This commit is contained in:
parent
568de58f36
commit
d14e810be0
|
@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -45,4 +45,4 @@ try {
|
|||
});
|
||||
} catch(e) {
|
||||
console.error('could not start server:', e);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue