-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic.js
More file actions
52 lines (40 loc) · 1.18 KB
/
basic.js
File metadata and controls
52 lines (40 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
'use strict';
/*
Sockets.io Client basic scripts
Connects to a remote socket server and stream random data to it
.. yes.. basic
./ minimal
./ basic
./ standalone
*/
var app_package = require('./package.json'),
nconf = require('nconf');
nconf.argv().env().file({file:'config.json'});
var io = require('socket.io-client'),
/*remote server */
socket = io.connect(nconf.get("SERVER_URL"), {
port: nconf.get("PORT")
});
// counting var
var send_sockets = 0;
function get_random(len){
var i;
var str = "";
var possible_b = "abc_341";
var possible = "<->";
len = Math.floor(Math.random()*20)+3
for( var i=0; i < len; i++ ){
str += possible_b.charAt(Math.floor(Math.random() * possible_b.length));
}
return str;
}
function say(){
send_sockets++; // increment 'global'
socket.emit('news', { action: 'socket_to_docTd', fk: 'temp_'+get_random(2), fv: get_random(5), doc_id: 13 , socketer_id :1, socketer_name:'Pi#0'});
console.log('~:~:~~:'+ send_sockets +' sockets sent and counting..')
setTimeout(say,3000); // every 3 seconds
}
socket.on('connect', function () {
console.log('~:~:~~: socket connected @ '+nconf.get("SERVER_URL")+':'+nconf.get("PORT"));
say();
});