websocket - Do web sockets still require repeated HTTP requests? -


i'm trying understand web sockets, having hard time grasping every part of process. on client side, we've got websocket object opens connection server. whenever there's new data, server delivers client, right?

that's good, in order there new data, server-side script has go it. in chat application, can see how works, since server being fed new messages time. if new data is, say, tweets?

in this application web page updated once second new twitter data. mean server-side script curling twitter api once second? seems weird considering overhead associated repeated http requests, , search limits twitter set.

in short, understand browser-server connection, don't understand how server gets new data unless there's script running on , on again.

this depends on application doing , third party apis interacts with.

generally, yes. if interacting third party http api still need poll periodically. can keep http keep-alive connection open should reduce latency significantly.

some services provide streaming apis can take advantage of in case. twitter example offer such streaming api. tweepy, twitter client used in example linked to, supports consuming twitter streaming api. allows new tweets without polling.

in case you're wondering how works, sends http request , gets infinite streaming response of newline-delimited json messages, can processed on fly.

other services may offer different streaming apis. if possible, favour streaming apis on polling, reduces latency , unnecessary network traffic.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -