all
I am very new to node.js. I am trying to make a tcp server client using node.js. So far, so good. The script server may work fine. You can also run the client script.
But the problem is that I could only get the client to work with the terminal by typing the command (node client.js).
The fact is that I would like to run it in a browser so that I can receive data received from displaying the server in the browser.
How to do it?
Please, help.
Kawin.
This is the client code. (I cannot remember who originally created this script. I copy and paste it from somewhere, but forget the bookmark from which I get the link. Sorry for not giving credit to the owner of this script.)
var net = require('net');
var HOST = '192.168.0.88';
var PORT = 8888;
var client = new net.Socket();
client.connect(PORT, HOST, function() {
console.log('CONNECTED TO: ' + HOST + ':' + PORT);
client.write('B2\r\n');
});
client.on('data', function(data) {
console.log('DATA: ' + data);
client.destroy();
});
client.on('close', function() {
console.log('Connection closed');
});
Thank.