-
-
Save nk-gears/48739c22f535bcc7d7043fd871c91f46 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const WebSocket = require('ws'); | |
const readline = require('readline'); | |
const url = process.argv[2]; | |
const ws = new WebSocket(url); | |
ws.on('open', () => console.log('connected')); | |
ws.on('message', data => console.log(`From server: ${data}`)); | |
ws.on('close', () => { | |
console.log('disconnected'); | |
process.exit(); | |
}); | |
readline.createInterface({ | |
input: process.stdin, | |
output: process.stdout, | |
}).on('line', data => { | |
const message = JSON.stringify({action: 'echo', data: input}); | |
ws.send(message); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment