Permalink
Browse files

becoming a real package soon

  • Loading branch information...
1 parent a4fee57 commit 5487574c8ba240c429e857d5424b3fb565d866a1 @peterbe committed Sep 6, 2012
View
19 LICENSE
@@ -0,0 +1,19 @@
+Copyright (C) 2012 Peter Bengtsson
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of
+this software and associated documentation files (the "Software"), to deal in
+the Software without restriction, including without limitation the rights to
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
+of the Software, and to permit persons to whom the Software is furnished to do
+so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
View
@@ -0,0 +1,96 @@
+django-sockjs-tornado
+=====================
+
+Makes it easy to run a SockJS server in Django through Tornado.
+
+This package is basically a thin wrapper on top of `sockjs-tornado
+<https://github.com/mrjoes/sockjs-tornado>`_ which makes it dead easy
+to write websocket based apps on top of the `sockjs Websocket
+emulation library <http://sockjs.org/>`_.
+
+With this wrapper you basically have access to everything else you
+need from your Django project such as your models and your various
+settings.
+
+Because you need to run two processes (one for `runserver` (or `wsgi`)
+and one for `socketserver`) it means that the two really are separate
+python processes so you can't easily do things like registering
+signals and trigger them in one process and have them fire in another.
+
+Getting started
+---------------
+
+Create a class somewhere that looks something like this::
+
+ from sockjs.tornado import SockJSConnection
+
+ class MyConnection(SockJSConnection):
+ def on_open(self, request):
+ pass
+ def on_message(self, message):
+ pass
+ def on_close(self):
+ pass
+
+Next, you need to put the loction of this in a setting in your
+`settings.py` something like this::
+
+ SOCKJS_CLASSES = (
+ 'myproject.myapp.myfile.MyConnection',
+ )
+
+
+Next, to start the server simply run::
+
+ python manage.py socketserver [--help]
+
+You'll still have your regular django server too in a separate terminal::
+
+ python manage.py runserver
+
+Now you should be able to write the juicy Javascript using
+`sockjs-client <https://github.com/sockjs/sockjs-client>`_. You can
+start by downloading the `latest minified version from the CDN
+<http://cdn.sockjs.org/>`_.
+
+A simple app might look like this::
+
+ sock = new SockJS('http://localhost:9999/echo');
+ sock.onmessage = function(e) {
+ console.log(e.data);
+ };
+ sock.onclose = function() {
+ console.log('closed :(');
+ };
+ sock.onopen = function() {
+ console.log('opened :>');
+ letTheMadnessBegin();
+ };
+
+ function letTheMadnessBegin() {
+ // silly, but you get the idea
+ sock.send(JSON.stringify({
+ name: $('#name').text(),
+ message: $('input').val()
+ }));
+ }
+
+Getting fancy
+-------------
+
+There's a shitload more things you can do with this of course. For
+example, you might want to add some form of authentication. Since the
+`on_open` handler receives a request you can use that to ask for
+`request.get_cookie()` which is left to the reader as an exercise.
+
+There is a slightly more fancy example included in this package under
+example which might get you some ideas. It's a fully working chat
+application that just works.
+
+This package is built mainly on `Serve Koval
+<https://github.com/mrjoes>`_'s amazing work on `sockjs-tornado
+<https://github.com/mrjoes/sockjs-tornado>`_ which has lots of more
+examples and documentation that might help you. For example, it lists
+to a sample HAProxy configuration which you might need once you take
+your project live since you can't keep exposing port 9999 on a
+production system.
@@ -0,0 +1 @@
+__import__('pkg_resources').declare_namespace(__name__)
@@ -0,0 +1 @@
+# Hi! I'm a django app!
@@ -119,7 +119,7 @@
# 'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
- 'django_tornado_sockets',
+ 'django_sockjs_tornado',
'project.chat',
)
View
@@ -0,0 +1 @@
+django
View
@@ -0,0 +1,42 @@
+#!/usr/bin/env python
+import os
+
+try:
+ from setuptools import setup, find_packages
+except ImportError:
+ from distribute_setup import use_setuptools
+ use_setuptools()
+ from setuptools import setup, find_packages
+
+try:
+ license = open('LICENSE').read()
+except:
+ license = None
+
+
+def read(fname):
+ return open(os.path.join(os.path.dirname(__file__), fname)).read()
+
+
+def desc():
+ return read('README.rst')
+
+setup(
+ name='django-sockjs-tornado',
+ version='0.0.1',
+ author='Peter Bengtsson',
+ author_email='mail@peterbe.com',
+ packages=['django_sockjs_tornado'],
+ namespace_packages=['django_sockjs_tornado'],
+ scripts=[],
+ url='http://github.com/peterbe/django-sockjs-tornado/',
+ license=license,
+ description='Makes it easy to run a SockJS server in Django through Tornado',
+ long_description=desc(),
+ requires=['tornado', 'sockjs'],
+ install_requires=[
+ 'tornado >= 2.1.1',
+ 'sockjs-tornado >= 0.0.4'
+ ],
+ zip_safe=False,
+)

0 comments on commit 5487574

Please sign in to comment.