Created
August 1, 2016 08:57
-
-
Save z3t0/5f3620629c7dc60d9d4ca02ad72523ab to your computer and use it in GitHub Desktop.
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
| // 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