GithubHelp home page GithubHelp logo

longpoll's Introduction

Long Polling

How does a client get information from a server when it becomes available?

Methods

  • Polling
  • Long Polling
  • Websockets

Polling

Polling is a naive attempt by the client if information is available from the server. The client will make periodic requests to the server. The server, in turn responds immediately with nothing, indicating the information is not available yet or with the desired data. Polling acts similarly to a child in the back of a car kicking the driver seat asking, "Are we there yet?" over and over, each time getting a response of "No."

Long Polling

Long polling is similar to polling in most ways. However, it attempts to be slightly smarter. Instead of the server responding immediately when it does not have information yet, it will wait until data is available before responding. From the client's perspective, this looks like a really long request. All other aspects of long polling act as standard polling.

Client Differences

  • Increased request timeout
  • Asychronous calls

Most of the differences between polling and long polling are on the server side. Polling does not request any special server implementation. However, long polling requires the server to purposefully hold a request and continually check for information before responding. In additional, the server now has to be more aware of memory management as it may be holding a number of requests while waiting for information to become available.

Server Differences

  • Holds request until information is available
  • Memory consumption is more of an issue

Note that long polling helps simulate "push" communication where a server would typically keep a registry of clients to notify if information becomes available. Long polling helps reduce the number of requests made to the server and does not request the server to keep a registry of clients to notify. Long polling acts similarly to a child in the back of a car kicking the driver seat asking, "Are we there yet?" over and over, each time, however, the driver waits some length of time before responding, "No." or "Yes."

Websockets

Websockets are an established, persistent connection between the client and the server. In this situation, the server is aware of the clients connected to it and can send information through this open channel when the data becomes available.

Running

  1. npm install && npm start (starts on port 1234)
  2. Open index.html in a browser

Note: Some of the features like queue and persistent are buggy. You may need to restart the server if it gets stuck.

longpoll's People

Contributors

bujiie avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.