Git Product home page Git Product logo

sinatra_sse_02's Introduction

Server-Sent Events

Demonstrate server-sent events with Sinatra. Both timer based events and Celluloid thread generated events are shown.

Github project: sinatra sse 02

Browser Demo pages

Celluloid Thread Event Source

Inline Timer Event Source

Run With JRuby and Trinidad Server

$ bundle exec ruby --1.9 --debug -S trinidad

Stand Alone test with curl

View the server-sent events

Celluloid actor based server-sent events

$ curl -i http://localhost:4000/actor/bubba

Output

HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
X-Frame-Options: sameorigin
X-XSS-Protection: 1; mode=block
Transfer-Encoding: chunked
Content-Type: text/event-stream;charset=utf-8
Transfer-Encoding: chunked
Date: Wed, 14 Dec 2011 23:20:09 GMT

data: {"source":"actor","time":"2011-12-14 15:20:09 -0800","id":"bubba"}

data: {"source":"actor","time":"2011-12-14 15:20:14 -0800","id":"bubba"}

data: {"source":"actor","time":"2011-12-14 15:20:22 -0800","id":"bubba"}

Timer based server-sent events

$ curl -i http://localhost:4000/timer/A_Label

Output

HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
X-Frame-Options: sameorigin
X-XSS-Protection: 1; mode=block
Transfer-Encoding: chunked
Content-Type: text/event-stream;charset=utf-8
Transfer-Encoding: chunked
Date: Thu, 15 Dec 2011 00:21:06 GMT

data: {"source":"timer","id":"A_Label","loop":1}

data: {"source":"timer","id":"A_Label","loop":2}

data: {"source":"timer","id":"A_Label","loop":3}

sinatra_sse_02's People

Contributors

cootcraig avatar

Stargazers

 avatar  avatar

Watchers

 avatar James Cloos 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.