var x = "[[Date.UTC(2013,5,2),0.7695],[Date.UTC(2013,5,3),0.7648],[Date.UTC(2013,5,4),0.7645],[Date.UTC(2013,5,5),0.7638],[Date.UTC(2013,5,6),0.7549],[Date.UTC(2013,5,7),0.7562],[Date.UTC(2013,5,9),0.7574]]";
var j = JSON.stringify(x);
console.log(j);
//"[[Date.UTC(2013,5,2),0.7695],[Date.UTC(2013,5,3),0.7648],[Date.UTC(2013,5,4),0.7645],[Date.UTC(2013,5,5),0.7638],[Date.UTC(2013,5,6),0.7549],[Date.UTC(2013,5,7),0.7562],[Date.UTC(2013,5,9),0.7574]]"
var x = [
[Date.UTC(2013,5,2),0.7695],
[Date.UTC(2013,5,3),0.7648],
[Date.UTC(2013,5,4),0.7645],
[Date.UTC(2013,5,5),0.7638],
[Date.UTC(2013,5,6),0.7549],
[Date.UTC(2013,5,7),0.7562],
[Date.UTC(2013,5,9),0.7574]
];
var j = JSON.stringify(x);
j
- настоящая, стопроцентная json-строка.console.dir(j);
// '[[1370131200000,0.7695],[1370217600000,0.7648],[1370304000000,0.7645],[1370390400000,0.7638],[1370476800000,0.7549],[1370563200000,0.7562],[1370736000000,0.7574]]'
["трололо", "1111"], ["пека", "222"]
- не формат JSON.[["трололо", "1111"], ["пека", "222"]]
- формат JSON.[ { "a": 12, "b": 38, "c": 345},
{ "a": 97, "b": 48, "c": 85},
{ "a": 56, "b": 2, "c": 934}]
setInterval(function() {
require('getModule').getData() // запускаю там запрос
.then( dataString => {
for (var key in clients) {
clients[key].send(dataString);
}
})
.catсh( err => {/* Не знаю чего тут */})ж
}, 5000);
setInterval(function() {
for (var key in clients) {
clients[key].send('Hello, World!!!');
}
}, 3000);
var socket = new WebSocket("ws://site.ru:8081");
var WebSocketServer = new require('ws');
var webSocketServer = new WebSocketServer.Server({
port: 8081
}, function() {console.log('ws-PORT = 8081')});
socket.onmessage = function(event) {
var incomingMessage = event.data;
// тут делаем с тем что пришло - что хотим
};
var clients = {};
...
WebSocketServer.on('connection', function(ws) {
var id = Math.pandom();
clients[id] = ws;
...
ws.on('message', function(msg) {
console.log('клиент ' + id);
...