diff --git a/bin/wscat b/bin/wscat index 79eb17d..edde590 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', appender(), []) .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); + + (program.message || []).forEach(function messager(s) { + ws.send(s); + wsConsole.print('> ' + s); + }); + 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(); });