javascript - Array being sent as String on node.js -
i doing experimenting socket.io. have canvas sends data server receives fine.
it receives uint8clampedarray correct because being sent.
when .send message server client, string: [object object]. again have checked! missing something, code server below:
var fs, http, io, server; fs = require('fs'); http = require('http'); server = http.createserver(function(req, res) { return fs.readfile("" + __dirname + "/front.html", function(err, data) { res.writehead(200, { 'content-type': 'text/html' }); return res.end(data, 'utf8'); }); }); server.listen(1337); io = require('socket.io').listen(server); io.sockets.on('connection', function(socket) { socket.on('publish', function(message) { return io.sockets.send(message); }); });
on client:
var datastr = json.stringify(data); // converts object string
on server:
var dataobj = json.parse(data); // converts string object
Comments
Post a Comment