Skip to content

Instantly share code, notes, and snippets.

@SREENATHPGS
Created August 18, 2019 11:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SREENATHPGS/1219d4435555fad46ca4c8947fbb87a9 to your computer and use it in GitHub Desktop.
Save SREENATHPGS/1219d4435555fad46ca4c8947fbb87a9 to your computer and use it in GitHub Desktop.
Web Socket client implemented in nodejs.
var WSclient = require('websocket').client;
var client = new WSclient();
client.on('connectionFailed', function(error) {
console.log('Connection Error: '+error.toString());
});
client.on('connect', function(connection) {
console.log('Connected');
connection.on('error', function(error) {
console.log("Connection Error: " + error.toString());
});
connection.on('close', function() {
console.log('echo-protocol Connection Closed');
});
connection.on('message', function(message) {
if (message.type === 'utf8') {
console.log('Received:-> '+message.utf8Data);
}
});
connection.sendUTF("Hi!, this is client!.");
});
console.log("Trying to connet to server...")
client.connect('ws://localhost:9090/', 'echo-protocol');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment