You have two options (others are described in detail above). In case you are not familiar with some of the conceptual ideas behind each option, I decided that I would tell them a couple of lines. Please note that I present these concepts at a very, very high level.
Your three options:
- Short poll
- Web socket
- Comet / long-polling
Short survey
A short survey overcomes the one-way communication between the Client-Server, forcing the client to continuously send requests to the form server:
Client: Do you have a message for me? Server: No. Client: (wait x seconds) Client: Do you have a message for me? Server: No. Client: (wait x seconds) Client: Do you have a message for me? Server: Yes. Here it is! Client: Yay! Client: (update message)
The constant grunt on behalf of the Client is called Poll . To implement this structure, you need to configure the server to "listen" to these polling requests from the client. The server will also need to store these messages somewhere, so that when the messages are ready, the server can deliver them. At a very high simplified level, your server needs to:
- Accept shared web requests
- Accept Survey Requests
- Running background jobs that retrieve messages
- Store these messages somewhere so that the server can check them when polling requests arrive.
You also need to associate these polling requests with some sort of session identifier for the user so that the right messages get to the right person. In general, the paradigm is complex and, in my opinion, ineffective.
Web sockets
Web sockets are new to HTML5. The main idea is that the Client can support a direct connection to the server, and they can transfer information to each other back and forth. Therefore, instead of the usual one: clients send a GET request โ The server responds with contents, web sockets allow maintaining a continuous dialogue.
To install this you need to:
- WebSocket compatible browsers (not all).
- A server that can handle web sockets (not sure how to state this, but not all servers are configured for this kind of arrangement).
The setup is somewhat complicated, although simpler than a lengthy survey:
- Client supports connection to a server that supports Web-Socket
- Server pushes results for client via web socket
- Customer Updates Page Based on Results
You will see that this template is called Push Notifications (of course, if you have an iPhone that you encountered), since the Server was authorized to click on the โstuffโ to the client (how impolite!). Since there are many nuances of the client and server, I would recommend testing something like Pusher , which is basically a web service for handling all the hard parts of web sockets. This will be an easy way to check and play with the template before proceeding with the configuration by yourself. It has both client and server libraries.
We hope that this information will give you a basic level to solve your problem. Other answers have more direct information on how to solve each scenario.
Comet / Long Poll
An alternative, seemingly cross-browser approach to web sockets is Long-Polling (see Comet ). In this case, your client establishes a connection to the server and leaves it hanging, waiting for data to be returned. The setup for this is a bit complicated, but it is the middle line between Short Poll and web sockets .