[Mod]完善Websocket服务
This commit is contained in:
parent
d88245db6e
commit
6eca19e337
@ -81,7 +81,7 @@ class Order(Resource):
|
||||
self.postParser.add_argument('offset')
|
||||
|
||||
self.deleteParser = reqparse.RequestParser()
|
||||
self.deletaParser.add_argument('vtOrderID')
|
||||
self.deleteParser.add_argument('vtOrderID')
|
||||
|
||||
super(Order, self).__init__()
|
||||
|
||||
@ -253,10 +253,8 @@ def handleEvent(event):
|
||||
"""处理事件"""
|
||||
eventType = event.type_
|
||||
eventData = event.dict_['data'].__dict__
|
||||
#socketio.emit(eventType, eventData, broadcast=True)
|
||||
socketio.emit('test', eventData, broadcast=True)
|
||||
|
||||
print eventData
|
||||
socketio.emit(eventType, eventData)
|
||||
#print eventData
|
||||
|
||||
|
||||
ee.register(EVENT_TICK, handleEvent)
|
||||
@ -272,5 +270,4 @@ ee.register(EVENT_ERROR, handleEvent)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(debug=True)
|
||||
#socketio.run(app)
|
||||
socketio.run(app)
|
@ -1,8 +1,10 @@
|
||||
# encoding: UTF-8
|
||||
|
||||
from socketIO_client import SocketIO, LoggingNamespace
|
||||
from socketIO_client import SocketIO, BaseNamespace
|
||||
from time import sleep
|
||||
from threading import Thread
|
||||
import logging
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def on_connect():
|
||||
@ -25,15 +27,37 @@ def 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__':
|
||||
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)
|
||||
#logging.getLogger('socketIO-client').setLevel(logging.DEBUG)
|
||||
#logging.basicConfig()
|
||||
|
||||
t = Thread(target=sio.wait)
|
||||
t.start()
|
||||
sio = SocketIO('127.0.0.1', 5000, TestNamespace, transports='websocket')
|
||||
sio.wait()
|
||||
|
||||
while True:
|
||||
sleep(1)
|
||||
|
@ -1,4 +1,4 @@
|
||||
# encoding: UTF-8
|
||||
|
||||
__version__ = '1.7.3'
|
||||
__version__ = '1.8.0'
|
||||
__author__ = 'Xiaoyou Chen'
|
Loading…
Reference in New Issue
Block a user