0

how to pipe tcp client data into http response ? cannot find complete example for that.

var oHttp = require("http")
    oHttp.createServer(function(req, res)
    {
    var query = req.url.split('?')[1];
    oTCP.write(query +'\n') ;
    }).listen(port);

get data from tcp client to http 'res' object using pipe :

var oNet  = require('net');
    oTCP = new oNet.Socket();
    oTCP.connect(PORT, HOST, function()
{
    console.log('TCP.client listen at port ' + PORT )
    this.pipe(res);
    });

got an error from node.js the 'this.pipe(res);' not defined on the object 'res'

what I want to achieve is :

  1. declare http serever
  2. connect once to tcp client.

  3. from http serever (req,res) cycle write to tcp client some query string

  4. get response from tcp client with pipe , to bypass the all on('data',...) event handlings so the pipe will 'know to target stream to 'res' streamer, if I understand.

in all the examples I see, that develoeprs are putting the tcp.connect inside the scope of the HTTP.createServer loop cycle ?? so it will make tcp connect on each (req,res) ?

I need make on once TCP connect and pipe to HTTP response's after each TCP.client write.

0 Answers0