Hi all I'm trying to send a javascript object through websockets:
the faye-websockets documentation says:
send(message) accepts either a String or a Buffer and sends a text or binary message over the connection to the other peer.
server side I'm using node and faye.
var WebSocket = require('faye-websocket');
var http = require('http');
var server = http.createServer();
server.addListener('upgrade', function(request, socket, head) {
var ws = new WebSocket(request, socket, head);
ws.send({topic:'handshake', data:'sdf487rgiuh7'});
});
server.listen(8000);
client side:
<script>
var ws = new WebSocket('ws://localhost:8000');
ws.onmessage = function(e) {
console.log(e.data); //prints [Object object] string and not the object
};
</script>
what is my error? Thanks