javascript - node js websock process -
i trying process data got in port. code :
var websocketserver = require('ws').server, wss = new websocketserver({ port: 5678 }); wss.on('connection', function connection(ws) { ws.on('message', function incoming(message) { function time_m() { var my_month=new date() var month_name=new array(12); month_name[0]="jan" month_name[1]="feb" month_name[2]="mar" month_name[3]="apr" month_name[4]="may" month_name[5]="jun" month_name[6]="jul" month_name[7]="aug" month_name[8]="sep" month_name[9]="oct" month_name[10]="nov" month_name[11]="dec" return month_name[my_month.getmonth()]; } function acc_array (n) { var arr_acc = new array ("xaxis", "yaxis", "zaxis"); return arr_acc[n]; } function sosjson() { function formatdate(d) { return d.getdate() + '-' + (time_m()) + "-" + d.getfullyear() + " " + d.gethours() + ":" + d.getminutes() + ":" + d.getseconds() + ":" + d.getmilliseconds() +" ist"; } var sosjsonobj = {}; var observations = []; var record = []; var output = []; var version = "1.0.1"; var sensor = "mysensor"; var starttime; var name; var value; sosjsonobj.version = version; sosjsonobj.observations = observations; observations[0] = {sensor, record}; var i; var msg = []; msg = message; console.log("reading array value of messgae"); console.log(msg[0]); (i = 0; < 3; i++) { //sleep(100); name = acc_array (i); value = msg; output.push({name, value}); starttime = formatdate(new date()); record.push({starttime, output}); } return json.stringify(sosjsonobj); } console.log('received: %s', message); }); sosjson(); ws.send('something'); });
but showed :
/home/root/node_modules/ws/websock_01.js:43 observations[0] = {sensor, record}; ^ syntaxerror: unexpected token , @ module._compile (module.js:439:25) @ object.module._extensions..js (module.js:474:10) @ module.load (module.js:356:32) @ function.module._load (module.js:312:12) @ function.module.runmain (module.js:497:10) @ startup (node.js:119:16) @ node.js:906:3
i not able find the issue having. node js not processing data. function calling guess not working properly. or else declaration may not correct.
the string observations[0] = {sensor, record};
not correct, if want object, should this: observations[0] = {sensor : sensor, record : record};
or array : observations[0] = [sensor, record];
in case better use object
Comments
Post a Comment