node.js - It is interesting to create a new node app to handle socket.io? -
i want add on existing project sockets nodejs , socket.io. have 2 servers :
- an api restful web service, storage , manage datas.
- a public web service return html, assets (js, css, images, ...)
on first try, create socket server on public one. think better if create other 1 handle socket query.
what think ? it's idea or useless add more problem solve (maybe duplicate intern lib, ..)
also, i'm using token communicate between public , api, have create communication between socket , api ? or can use same 1 ?
------[edit]------
as nobody didn't understand me have create schema infrastructure thinking about.
- it way proceed ?
- the public server , socket server have same ? or can separate ?
- do must create socket connection between api , socket server each client connected ?
thank !
thanks explaining better.
first of all, while seems reasonable, way of using socket.io not common one. biggest advantage of using socket.io keeps channel open 2-way communication. main advantage of server can send messages client without latter having poll periodically.
think, example, of mail client. without sockets, browser have poll periodically check new mail. open socket connection, instead, new mail comes server notifies client immediately.
in case, benefits limited, , i'm not sure additional complexity of socket.io server (and cost!) worth modest speed improvement on rest requests. however, @ end it's you.
in answer points
- see above
- if "public server" not written in node.js can't same application. wether reside on same server, it's , budget. ideally should separate, bigger workloads.
if want socket server act real-time proxy, yes, you'll have create socket connection each request. how work is:
- the client requests resource socket.io server.
- the socket.io server normal http request api server (e.g. using
request
) - the response returned client on socket connection
the workflow represented in #3 reason why should expect moderate performance improvement. indeed, you'll better latency, of overhead starting http request still there!
Comments
Post a Comment