Skip to content
Open
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
11 changes: 10 additions & 1 deletion bin/wscat
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ program
'enable slash commands for control frames (/ping [data], /pong [data], ' +
'/close [code [, reason]]) (--connect only)'
)
.option('-b, --binary', 'communicate with WebSocket server by binary data')
.option('-c, --connect <url>', 'connect to a WebSocket server')
.option(
'-H, --header <header:value>',
Expand Down Expand Up @@ -198,6 +199,7 @@ if (programOptions.listen) {

wsConsole.on('line', (data) => {
if (ws) {
if (programOptions.binary) data = Buffer.from(data, 'hex');
ws.send(data);
wsConsole.prompt();
}
Expand Down Expand Up @@ -231,6 +233,7 @@ if (programOptions.listen) {
});

ws.on('message', (data) => {
if (programOptions.binary) data = data.toString('hex');
wsConsole.print(Console.Types.Incoming, data, Console.Colors.Blue);
});
});
Expand Down Expand Up @@ -282,7 +285,11 @@ if (programOptions.listen) {

ws.on('open', () => {
if (programOptions.execute) {
ws.send(programOptions.execute);
if (programOptions.binary) {
ws.send(Buffer.from(programOptions.execute, 'hex'));
} else {
ws.send(programOptions.execute);
}
setTimeout(
() => {
ws.close();
Expand Down Expand Up @@ -338,6 +345,7 @@ if (programOptions.listen) {
);
}
} else {
if (programOptions.binary) data = Buffer.from(data, 'hex');
ws.send(data);
}
wsConsole.prompt();
Expand All @@ -363,6 +371,7 @@ if (programOptions.listen) {
});

ws.on('message', (data) => {
if (programOptions.binary) data = data.toString('hex');
wsConsole.print(Console.Types.Incoming, data, Console.Colors.Blue);
});

Expand Down