title: how to run node.js client on browser
body: <p>everyone</p>
  
  <p>I'm very new to node.js.
  I'm trying to do a tcp server &lt;-> client using node.js. So far so good.
  The server script can be run Ok.
  Also the client script can be run OK.</p>
  
  <p>But the problem is I could only get the client to run from the terminal by typing command (node client.js).<br>
  The thing is I would like to run it in a browser so I could take the data received from server display on browser.</p>
  
  <p>How do I do that?</p>
  
  <p>Please help.</p>
  
  <p>Kawin.</p>
  
  <p>This is the client code. (I can't remember who originally created this script. I copy and paste it from somewhere but forget to bookmark from which I get the link. Sorry for not putting the credit to the owner of this script.)</p>
  
  <pre><code>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);
      // Write a message to the socket as soon as the client is connected, the   server will receive it as message from the client 
      client.write('B2\r\n');
  });
  
  // Add a 'data' event handler for the client socket
  // data is what the server sent to this socket
  client.on('data', function(data) {
      console.log('DATA: ' + data);
      // Close the client socket completely
      client.destroy();
  });
  
  // Add a 'close' event handler for the client socket
  client.on('close', function() {
      console.log('Connection closed');
  }); 
  </code></pre>
  
  <p>Thank you.</p>