Skip to content

Instantly share code, notes, and snippets.

@z3t0
Created August 1, 2016 08:57
Show Gist options
  • Select an option

  • Save z3t0/5f3620629c7dc60d9d4ca02ad72523ab to your computer and use it in GitHub Desktop.

Select an option

Save z3t0/5f3620629c7dc60d9d4ca02ad72523ab to your computer and use it in GitHub Desktop.
// Nolag Client Implementation : Client
// Rafi Khan
// Require Modules
var WebSocket = require('ws')
// Returns Client Object
module.exports = function(host) {
return new Client(host)
}
function Client(host) {
// host is `ws://127.0.0.1:9002`
// Create Websocket
var ws = new WebSocket(host)
// Setup Callbacks
ws.on('open', this.onOpen)
ws.on('message', this.onMessage)
}
Client.prototype.onOpen = function() {
// Debug
console.log(`[CLIENT] Connected to server: `)
// Test connection
ws.send('Test message')
}
Client.prototype.onMessage = function(message) {
console.log(`[CLIENT] Got message: ${message}`)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment