title: Java -> TCP -> node.js (String data transfer)
body: <p>Client (Java)</p>
  
  <pre><code>Socket tcpClient = new Socket("localhost", 6000); 
  String msg ="test";
  DataOutputStream os = new DataOutputStream(tcpClient.getOutputStream());
  PrintWriter pw = new PrintWriter(os);
  pw.println(msg);
  pw.flush();
  </code></pre>
  
  <p>Server (node.js JavaScript)</p>
  
  <pre><code>var net = require('net');
  var server = net.createServer(function (c)
  { //'connection' listener
      log('Java client connected to this nodeServer');
      c.on('data', function (data)
      {
          console.log(data);   
      });
      c.on('end', function ()
      {
          console.log('nodeServer disconnected');
      });
  });
  server.listen(6000, function ()
  { //'listening' listener
      console.log('nodeServer listening port:6000');
  });
  </code></pre>
  
  <p>Result</p>
  
  <pre><code>nodeServer listening port:6000
  
  Java client connected to this nodeServer
  
  &lt;Buffer 74 65 73 74 0a&gt;
  </code></pre>
  
  <p>The connection succeeded, but obviously, I need 'test' string in Result.</p>
  
  <p>For the data, I use String so far to simplify my problem, however, it's ideal to be able to transfer any Objects.</p>
  
  <p>Perhaps, I need to use JSON framework (for non-binary object) to send over Java/TCP, but not sure.</p>
  
  <hr>
  
  <p>PS.
  this works by simply modifying to</p>
  
  <pre><code> var data1 = data.toString('utf-8');
   console.log(data1); 
  </code></pre>
  
  <p>Just to share.</p>