Created
August 18, 2019 11:34
-
-
Save SREENATHPGS/1219d4435555fad46ca4c8947fbb87a9 to your computer and use it in GitHub Desktop.
Web Socket client implemented in nodejs.
This file contains hidden or 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
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