Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env node
- var WebSocketClient = require('websocket').client;
- var client = new WebSocketClient();
- client.on('connectFailed', function(error) {
- console.log('Connect Error: ' + error.toString());
- });
- client.on('connect', function(connection) {
- console.log('WebSocket Client 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 + "'");
- }
- });
- function sendNumber() {
- if (connection.connected) {
- var number = Math.round(Math.random() * 0xFFFFFF);
- connection.sendUTF(number.toString());
- setTimeout(sendNumber, 1000);
- }
- }
- sendNumber();
- });
- client.connect('ws://194.228.153.100:9000/ws/text/75?access_token=67bde5d1b5f14520a565d03deae877fb', 'echo-protocol');
Advertisement
Add Comment
Please, Sign In to add comment