[Mod]完善Websocket服务

This commit is contained in:
vn.py 2018-01-22 17:34:49 +08:00
parent d88245db6e
commit 6eca19e337
3 changed files with 41 additions and 20 deletions

View File

@ -81,7 +81,7 @@ class Order(Resource):
self.postParser.add_argument('offset') self.postParser.add_argument('offset')
self.deleteParser = reqparse.RequestParser() self.deleteParser = reqparse.RequestParser()
self.deletaParser.add_argument('vtOrderID') self.deleteParser.add_argument('vtOrderID')
super(Order, self).__init__() super(Order, self).__init__()
@ -253,10 +253,8 @@ def handleEvent(event):
"""处理事件""" """处理事件"""
eventType = event.type_ eventType = event.type_
eventData = event.dict_['data'].__dict__ eventData = event.dict_['data'].__dict__
#socketio.emit(eventType, eventData, broadcast=True) socketio.emit(eventType, eventData)
socketio.emit('test', eventData, broadcast=True) #print eventData
print eventData
ee.register(EVENT_TICK, handleEvent) ee.register(EVENT_TICK, handleEvent)
@ -272,5 +270,4 @@ ee.register(EVENT_ERROR, handleEvent)
if __name__ == '__main__': if __name__ == '__main__':
app.run(debug=True) socketio.run(app)
#socketio.run(app)

View File

@ -1,8 +1,10 @@
# encoding: UTF-8 # encoding: UTF-8
from socketIO_client import SocketIO, LoggingNamespace from socketIO_client import SocketIO, BaseNamespace
from time import sleep from time import sleep
from threading import Thread from threading import Thread
import logging
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def on_connect(): def on_connect():
@ -25,15 +27,37 @@ def on_test(*args):
print 'on_test', args print 'on_test', args
########################################################################
class TestNamespace(BaseNamespace):
""""""
#----------------------------------------------------------------------
def on_connect(self):
"""连接"""
print 'on connect'
#----------------------------------------------------------------------
def on_disconnect(self):
"""断开"""
print 'disconnect'
#----------------------------------------------------------------------
def on_reconnect(self):
"""重连"""
print 'reconnect'
#----------------------------------------------------------------------
def on_message(self, *args):
"""测试"""
print 'on_message', args
if __name__ == '__main__': if __name__ == '__main__':
sio = SocketIO('127.0.0.1', 5000, LoggingNamespace) #logging.getLogger('socketIO-client').setLevel(logging.DEBUG)
sio.on('connect', on_connect) #logging.basicConfig()
sio.on('disconnect', on_disconnect)
sio.on('reconnect', on_reconnect) sio = SocketIO('127.0.0.1', 5000, TestNamespace, transports='websocket')
sio.on('test', on_test) sio.wait()
t = Thread(target=sio.wait)
t.start()
while True:
sleep(1)

View File

@ -1,4 +1,4 @@
# encoding: UTF-8 # encoding: UTF-8
__version__ = '1.7.3' __version__ = '1.8.0'
__author__ = 'Xiaoyou Chen' __author__ = 'Xiaoyou Chen'