proxy - node.js - communicate with TCP server (data == JSON) -


i'm new node.js, dived during last weekend , had fun various examples , small tutorials. i'd start little project local area network , have few questions myself right direction.

setup:
i've got server service running on lan. it's possible communicate service via tcp and/or http (it's possible enable or disable tcp or http or both of them) on specific port , sends , receives data via json on request. want create webinterface based on node.js service, receive , send json data webbrowser , service.

problem:
know how setup http server based on node.js. right i'm stuck in finding idea how create client based on node.js stands between service , webbrowser client pass through data client server , vise versa. router or proxy.

here basic scheme based on client's (webbrowser) point of view:

send: webbrowser requests -> node.js routes -> service receives
receive: webbrowser receives <- node.js routes <- service responds

questions:
- go tcp or http? (maybe disabling http server spare ressources) - maybe answered this post
- there node.js packages fit needs?
- go framework (expressions?) or plain node.js enough?
- hints appreciated :)
edit:
- possible bind network device eth0 inside node.js instead of defining ip address?

thanks && best regards
cefra

there's no reason why can't have rest http service.

use express handle routing.

if understand problem correctly have webservice written in "foobar" on tcp port somewhere can connect node.

so if using express write like

app.get("/resources/", function(req, res) {     var socket = new net.socket();     socket.connect(port, host, function() {         socket.on("data", function(json) {             res.contenttype("json");             res.send(json);             socket.end();         });         socket.write(...);     }); }); 

so you've written http middleman contacts service on tcp writes data down response of http request.


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -