I have created my web socket server and client using this simple tutorial here : http://cjihrig.com/blog/creating-your-own-node-js-websocket-echo-server/
But it seems like it recognises only UTF-8 characters.
I want to send JSON message in the text box:
var jsonString = JSON.stringify({"fname":"John","lname":"Smith"})
and in ws_server.js file, I have written
connection.on('message', function(message) {
var jObject = JSON.parse(message);
jObject.lname = "Jobs";
}..
But I am getting error for JSON.parse method.
Please let me know what is the problem.
Or do I have to write any new server implementation for JSON parsing or JSON messages?
This is my client code: http://cjihrig.com/blog/creating-your-own-websocket-echo-client/
but value of "text" is modified to be as follows:
jsonmsg = {fname:"John",lname:"Smith"}
jsonString = JSON.stringify(jsonmsg);
So socket.send(jsonString);
Thanks
Sneha
var jsonString = {"fname":"John","lname":"Smith"}
does not create a string; it creates an object. To make it a string:
var jsonString = JSON.stringify({"fname":"John","lname":"Smith"})
Have you tried:
socket.json.send( { fname : 'John', lname : 'Smith'} );