I have a device that says following points its api documentation:
1. Use websocket protocol to communication,the websocket version is RFC6455 13,The default listen port is 7788,no TLS encrypt.
2. The data format use Json.you can use javascript to Serializer and Deserialize very easy.
3. All the key value of json use lower-char.the name or all chinese char use UTF8 encoded.
I am creating nodejs app as a server to this device.
var net = require("net");
var server = net.createServer();
server.on("connection",function(socket){
socket.on("data",function(d){
console.log("Data from %s : %s", remoteAddress,d);
socket.write(
{
"cmd":"getuserlist",
"stn":true
}
);
});
});
server.listen(9000,function(){
console.log("Server listening to port %j", server.address());
});
The device is being connected. After connection i am sending json data to the device and according to the documentation it also needs to respond json data but it is not working. Please help me to get the response. Further i neeed to call to an url by parsing the json response. let me make clear.
//If i get response like:
success:{
"count":40,
}
//I need to call an url like:
"http://example.com/40/"
How can i achieve it ?
P.S: I am new to node.js
remoteAddressis not declared,socket.writeaccepts only string-s (tryJSON.stringify({...}))