From ea02ee6681cac01cb7184b434b64f6c8df09fa9c Mon Sep 17 00:00:00 2001 From: Espen Henriksen Date: Wed, 27 Jan 2016 20:56:20 +0100 Subject: [PATCH 1/2] Add -m (Send initial message) --- bin/wscat | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/bin/wscat b/bin/wscat index 79eb17d..628712e 100755 --- a/bin/wscat +++ b/bin/wscat @@ -106,6 +106,7 @@ program .usage('[options] (--listen | --connect )') .option('-l, --listen ', 'listen on port') .option('-c, --connect ', 'connect to a websocket server') + .option('-m, --message ', 'initial message to send') .option('-p, --protocol ', 'optional protocol version') .option('-o, --origin ', 'optional origin') .option('--host ', 'optional host') @@ -199,6 +200,12 @@ if (program.listen && program.connect) { ws.on('open', function open() { wsConsole.print('connected (press CTRL+C to quit)', Console.Colors.Green); + + if (program.message) { + ws.send(program.message); + wsConsole.print('> ' + program.message); + } + wsConsole.on('line', function line(data) { ws.send(data, { mask: true }); wsConsole.prompt(); @@ -218,7 +225,7 @@ if (program.listen && program.connect) { if (!ws) return; try { ws.close(); } - catch(e) {} + catch(e) {} process.exit(); }); From 7907ef1453bf545ce5a54290ffd1653fa604b28d Mon Sep 17 00:00:00 2001 From: Espen Henriksen Date: Fri, 29 Jan 2016 16:51:39 +0100 Subject: [PATCH 2/2] Add ability to provide several -m's --- bin/wscat | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/bin/wscat b/bin/wscat index 628712e..edde590 100755 --- a/bin/wscat +++ b/bin/wscat @@ -106,7 +106,7 @@ program .usage('[options] (--listen | --connect )') .option('-l, --listen ', 'listen on port') .option('-c, --connect ', 'connect to a websocket server') - .option('-m, --message ', 'initial message to send') + .option('-m, --message ', 'initial message to send', appender(), []) .option('-p, --protocol ', 'optional protocol version') .option('-o, --origin ', 'optional origin') .option('--host ', 'optional host') @@ -201,10 +201,10 @@ if (program.listen && program.connect) { ws.on('open', function open() { wsConsole.print('connected (press CTRL+C to quit)', Console.Colors.Green); - if (program.message) { - ws.send(program.message); - wsConsole.print('> ' + program.message); - } + (program.message || []).forEach(function messager(s) { + ws.send(s); + wsConsole.print('> ' + s); + }); wsConsole.on('line', function line(data) { ws.send(data, { mask: true });