Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion bin/wscat
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ program
.usage('[options] (--listen <port> | --connect <url>)')
.option('-l, --listen <port>', 'listen on port')
.option('-c, --connect <url>', 'connect to a websocket server')
.option('-m, --message <message>', 'initial message to send', appender(), [])
.option('-p, --protocol <version>', 'optional protocol version')
.option('-o, --origin <origin>', 'optional origin')
.option('--host <host>', 'optional host')
Expand Down Expand Up @@ -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();
Expand All @@ -218,7 +225,7 @@ if (program.listen && program.connect) {
if (!ws) return;

try { ws.close(); }
catch(e) {}
catch(e) {}

process.exit();
});
Expand Down