Created
April 13, 2012 15:07
-
-
Save Gautier/2377543 to your computer and use it in GitHub Desktop.
example websocket
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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