Giter Club home page Giter Club logo

cramp_chat_demo's Introduction

Cramp Chat Demo

Cramp is an asynchronous web framework still under development by Pratik Naik which shows great promise for its use of EventMachine.

This is just a proof-of-concept app to showcase Cramp’s potential.

Usage

This should install all the dependencies

  bundle install

This demo uses MySQL, so you will need to create your own database. Read config/database.sql to create it and edit config/database.yml with the correct server, username and password.

If you want to test the WebSocket implementation outside of Google Chrome 4+, the app loads web-socket.js. As it uses Flash connection it is required that the server provides a policy file. This app uses Peleus Uhley implementation available in the extra folder. Start it like this:

  cd extra
  sudo python flashpolicyd.py --port 843 --file crossdomain.xml

It has to be sudo because 843 is a privileged port. Now you need to start up the application itself:

  ruby chatserver.rb

It will start the server on the port 3000. So you can fire up a webbrowser and use either of these URLs:

  http://0.0.0.0:3000/chat
  http://0.0.0.0:3000/chat_poll

The first URL is the WebSocket version. The second is a more usual Ajax Polling version, which may be more compatible with webbrowsers. As the WebSocket version uses Flash it’s less friendly to environments behind proxies and firewalls.

You can also test the server using curl

  curl http://0.0.0.0:3000/websocket
  curl http://0.0.0.0:3000/retrieve
  curl -d "from=foo&msg=hello" http://0.0.0.0:3000/receive

The first URL will keep an open HTTP connection, receiving new messages as they are inserted in the database. The second one retrieves the last few messages and you can pass a ‘last_timestamp’ parameter to the URL with the value having the format of Time.now.to_formatted_s(:db). Finally, the third operation simulates a form post to add new messages. The first URL is the WebSocket version, the last 2 are the polling version.

Known Issues

  • In Firefox and Safari, I had the web-socket.js working properly, but for some reason it stopped working. Beware of flash blockers in your browser.
  • In the Polling version it is manually setting the last message’s timestamp in the URL. I was still now able to make a version using a Rack::Session
  • Just because it is a proof-of-concept, it uses Rack::Static to serve the HTML and JS files, but it’s not certain that this is the best way to do it
  • Up until Cramp 0.9, it depends on ActiveRecord, take a look at lib/fixes.rb

TODO

  • Add CSS to make the demo a little bit more compelling
  • Add multiple room and user registration support, but this requires exchanging session information as well. Making Rack::Session work may be a requirement
  • Add templating than just static file to allow for some HAML or ERB views, adding Tilt to Cramp would be good as well

Changelog

  • 02/14/2011 – Updated to Cramp 0.12 and the new Tramp gem.

Credits

cramp_chat_demo's People

Contributors

akitaonrails avatar lifo avatar

Watchers

Raphael Silva 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.