Skip to content

Instantly share code, notes, and snippets.

@Gautier
Created April 13, 2012 15:07
Show Gist options
  • Save Gautier/2377543 to your computer and use it in GitHub Desktop.
Save Gautier/2377543 to your computer and use it in GitHub Desktop.
example websocket
from django.core.management import setup_environ
from asyncdb import settings
setup_environ(settings)
from core.models import Help
from eventlet import wsgi
import eventlet
import websocket
i = 0
@websocket.WebSocketWSGI
def dispatch(ws):
global i
Help.objects.create(user="bob %d" % i, checked=False)
i += 1
ws.wait()
ws.send("Hi, I have %d helps" % Help.objects.all().count())
ws.close()
if __name__ == '__main__':
Help.objects.all().delete()
listener = eventlet.listen(('127.0.0.1', 8000))
wsgi.server(listener, dispatch)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment