From 133bd6f3098e1c9067eb124fbde04b184187ad08 Mon Sep 17 00:00:00 2001 From: Roy Hyunjin Han Date: Thu, 18 Apr 2013 07:32:46 -0700 Subject: [PATCH] Added emit with callback in serve_tests --- TODO.goals | 3 +++ serve_tests.py | 17 +++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/TODO.goals b/TODO.goals index 7ae3dbd..502f59f 100644 --- a/TODO.goals +++ b/TODO.goals @@ -1,5 +1,8 @@ = Resolve pull requests = Resolve pull request #6 + Add unit test for handling server callback + + Add emit with callback in serve_tests + Use json with ensure_ascii=False Resolve issues Investigate issue #8 Examine forks diff --git a/serve_tests.py b/serve_tests.py index 24df950..35bf41d 100644 --- a/serve_tests.py +++ b/serve_tests.py @@ -4,10 +4,11 @@ try: from socketio.namespace import BaseNamespace from socketio.server import SocketIOServer except ImportError: + import sys from setuptools.command import easy_install easy_install.main(['-U', 'gevent-socketio']) print('\nPlease run the script again to launch the test server.') - import sys; sys.exit(1) + sys.exit(1) class Namespace(BaseNamespace): @@ -15,8 +16,13 @@ class Namespace(BaseNamespace): def on_aaa(self, *args): self.emit('aaa_response', *args) + def on_bbb(self, *args): + def callback(*args): + self.emit('callback_response', *args) + self.emit('bbb_response', *args, callback=callback) -class Application(object): + +class App(object): def __call__(self, environ, start_response): socketio_manage(environ, { @@ -29,5 +35,8 @@ class Application(object): if __name__ == '__main__': from socketIO_client.tests import PORT print 'Starting server at port %s' % PORT - socketIOServer = SocketIOServer(('0.0.0.0', PORT), Application()) - socketIOServer.serve_forever() + try: + server = SocketIOServer(('0.0.0.0', PORT), App()) + server.serve_forever() + except KeyboardInterrupt: + pass