title: creating a tcp socket with net.createConnection(port, [host]) in node.js
body: <p>Anyone here can give me a few pointers working with sockets in node.js?  </p>
  
  <p>can open a tcp connection say on 172.0.0.1 on port 8000 for example using net.createConnection(port, host)</p>
  
  <pre><code>var net = require('net'),
      querystring = require('querystring'),
      http = require('http'),
      port = 8383,
      host = 172.123.321.213,
      path = /path/toService,
      _post = '';
  
  var server = http.createServer(function(req, res) {
  
      if(req.method == 'POST') {
        req.on('data', function(data) {
          body+=data;
        });
        req.on('end', function() {
          _post = querystring.parse(body);//parser post data
          console.log(_post);
        })
      }
  
  var socket = net.createConnection(port, host);
  
  var socket = net.createConnection(port, host);
  
      socket.on('error', function(error) {
        send404(res, host, port);
      })
  
      socket.on('connect', function(connect) {
        console.log('connection established');
        res.writeHead(200, {'content-type' : 'text/html'});
        res.write('&lt;h3&gt;200 OK: 
             Connection to host ' + host + ' established. Pid = ' + process.pid + '&lt;/h3&gt;\n');
        res.end();
        var body = '';
        socket._writeQueue.push(_post);
  
        socket.write(_post);
  
        console.log(socket);
  
        socket.on('end', function() {
          console.log('socket closing...')
        })
      })
  
      socket.setKeepAlive(enable=true, 1000);
    }).listen(8000);
  
    send404 = function(res, host, port) {
      res.writeHead(404, {'content-type': 'text/html'});
      res.write('&lt;h3&gt;404 Can not establish connection to host: ' + host + ' on port: ' + port + '&lt;/h3&gt;\n');
      res.end();
    }
  </code></pre>
  
  <p>But now I need to send my data to the path defined - if I add the path to host then try connection then connection will fail.</p>
  
  <p>Any ideas?</p>
  
  <h2>Thanks in advance</h2>