简体   繁体   中英

How do server-client push/pull connections work?

I'm very interested in how financial data is streamed from server to client. I often here the term 'push-pull' used. I wondered if someone could give me an example (preferably in Java, C# or perhaps Javascript) how this is actually achieved? Whenever I have written amateur hobby projects at home I often end up querying a URL (containing the price) and continuously calling this within a while(true) loop, with a thread.sleep(x), even if the price doesnt change.

Thanks in advance

Don't know what you mean with 'streaming financial data', but the concept of push/pull is not limited to the financial sector:)

Generally speaking, pull strategy means that the client is actively getting data through a pre-defined communication channel (in your case a socket to an existing and known URL) and polling this channel for new information.

In contrast to that you have the push strategy where you are notified of any changes and you supply the communication channel and register it with the connection's partner. Eg you have a webservice and your connection partner will post information to that webservice whenever he sees fit. See http://en.wikipedia.org/wiki/Observer_pattern for this concept.

Hope this helps a bit.

If client is working over HTTP the push is always initiated by client, ie client requests new updates and server sends them. If client is thin client (ie application running in browser) the modern way is to use AJAX to retrieve data without refreshing the page. But again the initiative is at client side, but user just does not see it. It is done on scheduled basis using javascript.

The most "real time" approach is using HTTP tunneling technique: client performs HTTP GET to special URL mapped to servlet that does not close the connection. It just holds it open. When it has something to send to client it writes to stream. So, you get server-to-client push, but still initial connection was performed by client.

You were doing pull. Pulling is when the clients request the data from the server and the server acts on that request.

If the server would have send you data upon receiving new data, that would have been push .

So the difference is: push is initiated by the server and pull is initiated by the client.

Financial data is often transmitted with software like TIBCO Rendezvous . A publisher sends the message to a daemon and listeners that subscribed that subject gets the message from the daemon.

These are the two web-based PUSH techniques.

As for browser support:

  • Chrome/Safari/Firefox6 support Both of those.
  • Opera supports EventSource and Websockets but has the latter disabled by default.
  • Firefox 4 supports websockets but has it disabled by default.
  • IE<10 supports neither, IE10 might support one if your lucky

There are many pull techniques, including HTTP and ajax.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM