From d88245db6eb9b216b94b98eab33f9a20fef133fc Mon Sep 17 00:00:00 2001 From: "vn.py" Date: Sun, 21 Jan 2018 19:06:47 +0800 Subject: [PATCH] =?UTF-8?q?[Add]=E5=A2=9E=E5=8A=A0SocketIO=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/WebTrader/run.py | 8 ++++++-- examples/WebTrader/test.py | 39 ++++++++++++++++++++++++++++++++++++++ requirements.txt | 4 +++- 3 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 examples/WebTrader/test.py diff --git a/examples/WebTrader/run.py b/examples/WebTrader/run.py index af23aa4a..0a7152f3 100644 --- a/examples/WebTrader/run.py +++ b/examples/WebTrader/run.py @@ -253,7 +253,10 @@ def handleEvent(event): """处理事件""" eventType = event.type_ eventData = event.dict_['data'].__dict__ - socketio.emit(eventType, eventData, broadcast=True) + #socketio.emit(eventType, eventData, broadcast=True) + socketio.emit('test', eventData, broadcast=True) + + print eventData ee.register(EVENT_TICK, handleEvent) @@ -269,4 +272,5 @@ ee.register(EVENT_ERROR, handleEvent) if __name__ == '__main__': - app.run(debug=True) \ No newline at end of file + app.run(debug=True) + #socketio.run(app) \ No newline at end of file diff --git a/examples/WebTrader/test.py b/examples/WebTrader/test.py new file mode 100644 index 00000000..c5be3e68 --- /dev/null +++ b/examples/WebTrader/test.py @@ -0,0 +1,39 @@ +# encoding: UTF-8 + +from socketIO_client import SocketIO, LoggingNamespace +from time import sleep +from threading import Thread + +#---------------------------------------------------------------------- +def on_connect(): + """连接""" + print 'on connect' + +#---------------------------------------------------------------------- +def on_disconnect(): + """断开""" + print 'disconnect' + +#---------------------------------------------------------------------- +def on_reconnect(): + """重连""" + print 'reconnect' + +#---------------------------------------------------------------------- +def on_test(*args): + """测试""" + print 'on_test', args + + +if __name__ == '__main__': + sio = SocketIO('127.0.0.1', 5000, LoggingNamespace) + sio.on('connect', on_connect) + sio.on('disconnect', on_disconnect) + sio.on('reconnect', on_reconnect) + sio.on('test', on_test) + + t = Thread(target=sio.wait) + t.start() + + while True: + sleep(1) diff --git a/requirements.txt b/requirements.txt index 180feca0..530b5a60 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,4 +5,6 @@ qdarkstyle SortedContainers futuquant wmi -future \ No newline at end of file +future +flask-socketio +flask-restful \ No newline at end of file