Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

Our architecture is HTTP servers (custom written) which whereby custom clients send a HTTP request for some information and information is returned just as HTTP works. But we need a special custom 'extension' which is a request which is a subscription for receiving asynchronous 'events' on a resource.

For example the client sends an http request subscribing for events on some entity. As the 'entity' generates events they are passed to the http server and the http server must then lookup subscriptions for that entity and send the event message to all subscribed clients. Hope that makes sense.

So my questions are:

  • Has this been done before / or is there a standard I should be looking at?
  • If no standard, any suggestions on how to implement?
  • How does a http server send an unsolicited 'message' to a client?
share|improve this question
1  
So implementing the Observer pattern en.wikipedia.org/wiki/Observer_pattern? –  StuperUser Nov 18 '11 at 16:18

4 Answers 4

up vote 0 down vote accepted

There is a draft for such a standard in HTML5, called "Server Sent Events"

Read all about it here: http://dev.w3.org/html5/eventsource/

share|improve this answer

It's really not what HTTP, as a connectionless protocol, was designed for so you may want to consider using something else for this type of communication, for example the XMPP protocol, or an enterprise messaging solution such as RabbitMQ.

share|improve this answer

You can't (that I know of) open an unsolicited CONNECTION (as in socket connection) to an HTTP client. You can, however, send unsolicited MESSAGES across a channel the client has left open. This concept is called Comet.

This pattern works nicely, and it should be able to provide the kind of pub-sub updates you are talking about.

share|improve this answer

HTTP protocol is an application layer protocol, and it sounds like what you want isn't really HTTP at all.

Just open a simple TCP/IP connection socket and have the client on a seperate thread listen for messages from the server. There are also plenty of frameworks as others are pointing out that will handle this complexity for you.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.