send a ping to test
This commit is contained in:
@ -6,6 +6,8 @@ const OPCODES = {
|
||||
HANDSHAKE: 0,
|
||||
FRAME: 1,
|
||||
CLOSE: 2,
|
||||
PING: 3,
|
||||
PONG: 4,
|
||||
};
|
||||
|
||||
let PipePath;
|
||||
@ -47,9 +49,17 @@ class RpcMessage {
|
||||
return RpcMessage.serialize(opcode, {code, message});
|
||||
}
|
||||
|
||||
static sendPing(message) {
|
||||
const opcode = OPCODES.PING;
|
||||
return RpcMessage.serialize(opcode, {message});
|
||||
}
|
||||
|
||||
static deserialize(buff) {
|
||||
const opcode = buff.readInt32LE(0);
|
||||
const msgLen = buff.readInt32LE(4);
|
||||
if (msgLen == 0) {
|
||||
return {opcode, data: ''};
|
||||
}
|
||||
if (buff.length < (msgLen + 8)) {
|
||||
return null;
|
||||
}
|
||||
|
@ -58,3 +58,18 @@ replServer.defineCommand('kill', {
|
||||
}
|
||||
});
|
||||
|
||||
replServer.defineCommand('ping', {
|
||||
help: 'Ping all clients',
|
||||
action() {
|
||||
this.bufferedCommand = '';
|
||||
Object.keys(global.connections).forEach((who) => {
|
||||
const sock = global.connections[who];
|
||||
if (sock) {
|
||||
console.log('pinging', who);
|
||||
sock.write(RpcMessage.sendPing('hello'));
|
||||
}
|
||||
})
|
||||
this.displayPrompt();
|
||||
}
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user