Zinc-Server-Sent-Events

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Zinc-Server-Sent-Events

Sven Van Caekenberghe-2
Hi,

Server-Sent Events is a new HTML5 technology that is used to send data from a server to a client, over HTTP, on the initiative of the server.

Here are some references:

 http://en.wikipedia.org/wiki/Server-sent_events
 http://dev.w3.org/html5/eventsource/
 https://developer.mozilla.org/en-US/docs/Server-sent_events/Using_server-sent_events

Zinc-Server-Sent-Events is a proof of concept implementation with a small demo of Server-Sent Events for Zinc HTTP Components in Pharo.

Usage in quite simple: you specify a handler object that implements a #run: method for each outgoing feed, like this

run: connection
  "Using Server-Sent Events is simple: keep a reference to the connection,
  instanciate ZnServerSentEvent objects and use #writeOn: to push them out."
       
  | event status |
  [
    status := self statusString.
    event := ZnServerSentEvent type: 'status-update' data: status.
    event writeOn: connection.
    2 seconds asDelay wait ] repeat

On the client side, a standard JavaScript listener will receive the incoming events.

The package can be found here

  http://www.smalltalkhub.com/#!/~SvenVanCaekenberghe/ZincHTTPComponents/packages/Zinc-Server-Sent-Events

Make sure to update Zinc itself to its bleedingEdge first.

Sven

--
Sven Van Caekenberghe
http://stfx.eu
Smalltalk is the Red Pill