require('crypto'); var CEXWebsocketURL = 'wss://ws.cex.io/ws/'; var WebSocketClient = require('ws'); //require('websocket').client; var client = new WebSocketClient(CEXWebsocketURL); client.on('connectFailed', function(error) { console.log('Connect Error: ' + error.toString()); }); client.on('open', function open() { client.send('something'); }); client.on('message', function incoming(data) { console.log(data); }); client.on('connect', function(connection) { console.log('WebSocket Client Connected', connection); // Connection error connection.on('error', function(error) { console.log("Connection Error: " + error.toString()); }); // Connection closed connection.on('close', function() { console.log('echo-protocol Connection Closed'); }); // Connection incoming message connection.on('message', function(message) { if (message.type === 'utf8') { console.log("Received: '" + message.utf8Data + "'"); } }); // function sendNumber() { // if (connection.connected) { // var number = Math.round(Math.random() * 0xFFFFFF); // connection.sendUTF(number.toString()); // setTimeout(sendNumber, 1000); // } // } // sendNumber(); }); //client.connect(CEXWebsocketURL);