Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add option -b/--binary for communicate with WebSocket server by binary data #159

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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