c++ - Async RestFul vs Websocket -
i implementing client-server api long job processing times (order of minutes in cases). of api calls short , respond coupe require back-end processing. using node.js web server. current implementaion follows -
client(browser) <-> node js <-> engine
the engine back-end process processes each job (c++ code). interactions http. now, traditionally implement long jobs async ajax/restful requests , short jobs sync restful requests.
i going have status updates long processing jobs (processing large data) - intermediate results, percent complete etc.
i loolking @ websockets alternative (and relatively new it). here questions -
- should websockets long jobs instead of async restful api (i love avoid handling client-timeouts, long-polling etc.) ?
- how moving requests websockets (why bother rest @ all? )
- in general, best practices implement architecture. (previously, worked on projects interaction between webserver , engine simple tcp connection custom commands.)
note:- not worried cross-browser support (especially older versions) right now.
i've implemented client-server api using websockets communicate between browser , c++ backend. library used libwebsockets http://git.warmcat.com/cgi-bin/cgit/libwebsockets/
both long running , simultaneous commands worked on websockets. multiple requests can sent client , server can respond when ready , can send responses out of order (or coalesce responses single response).
the timeout & long-polling stuff necessary ajax becomes simpler e.g. client disconnections can detected server when socket broken.
as best practices, based design on these articles. used json encode messages.
- http://www.altdevblogaday.com/2012/02/01/controlling-your-game-engine-over-websocket/
- http://www.altdevblogaday.com/2012/01/23/writing-your-own-websocket-server/
if server node.js socket.io. abstracts communication layer , can pick between ajax, websockets etc depending on what's available.
Comments
Post a Comment