本文整理汇总了Python中socketIO_client.SocketIO.message方法的典型用法代码示例。如果您正苦于以下问题:Python SocketIO.message方法的具体用法?Python SocketIO.message怎么用?Python SocketIO.message使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类socketIO_client.SocketIO
的用法示例。
在下文中一共展示了SocketIO.message方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Transaction
# 需要导入模块: from socketIO_client import SocketIO [as 别名]
# 或者: from socketIO_client.SocketIO import message [as 别名]
class Transaction(object):
def __init__(self):
self.custom_timers = {}
self.word_list = buildArray( )
self.word_list_length = len(self.word_list)
self.socketIO = SocketIO(HOST, PORT)
self.socketIO.define(Namespace)
def makeCall( self, jsonObject ):
start_timer = time.time()
self.socketIO.message(jsonObject)
self.socketIO.wait(0.01)
namespace = self.socketIO.get_namespace()
#print namespace.response
latency = time.time() - start_timer
self.custom_timers['trie_service_sockets'] = latency
#if latency > 5:
#writeErrorInfo('latency value of %f with %s' %(latency, url) )
#if r.status_code != 200:
#writeErrorInfo('status code with %s is %s' %(r.status_code, url) )
#assert (r.status_code == 200), 'Bad HTTP Response'
#assert ('suggestions' in namespace.response), 'No suggestions'
def run(self):
#get a random word from the word_list and call to typeahead
whichPhrase = random.randrange(0,self.word_list_length)
phrase = self.word_list[whichPhrase]
word = phrase.split(" ")[0]
#print 'word is %s' % word
message = ""
jsonObject = ""
#loop through the chars in the word skipping the first
#for char in word:
# message = message + char
# jsonObject = {'@class': 'com.glg.service.TrieObject', 'entity':'cm', 'prefix':message}
# self.makeCall( jsonObject )
jsonObject = {'@class': 'com.glg.service.TrieObject', 'entity':'cm', 'prefix':word}
self.makeCall( jsonObject )
示例2: TestSocketIO
# 需要导入模块: from socketIO_client import SocketIO [as 别名]
# 或者: from socketIO_client.SocketIO import message [as 别名]
class TestSocketIO(TestCase):
def setUp(self):
self.socketIO = SocketIO(HOST, PORT)
self.called_on_response = False
def tearDown(self):
del self.socketIO
def on_response(self, *args):
self.called_on_response = True
for arg in args:
if isinstance(arg, dict):
self.assertEqual(arg, PAYLOAD)
else:
self.assertEqual(arg, DATA)
def is_connected(self, socketIO, connected):
childThreads = [
socketIO._rhythmicThread,
socketIO._listenerThread,
]
for childThread in childThreads:
self.assertEqual(not connected, childThread.done.is_set())
self.assertEqual(connected, socketIO.connected)
def test_disconnect(self):
'Terminate child threads after disconnect'
self.is_connected(self.socketIO, True)
self.socketIO.disconnect()
self.is_connected(self.socketIO, False)
# Use context manager
with SocketIO(HOST, PORT) as self.socketIO:
self.is_connected(self.socketIO, True)
self.is_connected(self.socketIO, False)
def test_message(self):
'Message'
self.socketIO.define(Namespace)
self.socketIO.message()
self.socketIO.wait(0.1)
namespace = self.socketIO.get_namespace()
self.assertEqual(namespace.response, 'message_response')
def test_message_with_data(self):
'Message with data'
self.socketIO.define(Namespace)
self.socketIO.message(DATA)
self.socketIO.wait(0.1)
namespace = self.socketIO.get_namespace()
self.assertEqual(namespace.response, DATA)
def test_message_with_payload(self):
'Message with payload'
self.socketIO.define(Namespace)
self.socketIO.message(PAYLOAD)
self.socketIO.wait(0.1)
namespace = self.socketIO.get_namespace()
self.assertEqual(namespace.response, PAYLOAD)
def test_message_with_callback(self):
'Message with callback'
self.socketIO.message(callback=self.on_response)
self.socketIO.wait_for_callbacks(seconds=0.1)
self.assertEqual(self.called_on_response, True)
def test_message_with_callback_with_data(self):
'Message with callback with data'
self.socketIO.message(DATA, self.on_response)
self.socketIO.wait_for_callbacks(seconds=0.1)
self.assertEqual(self.called_on_response, True)
def test_emit(self):
'Emit'
self.socketIO.define(Namespace)
self.socketIO.emit('emit')
self.socketIO.wait(0.1)
self.assertEqual(self.socketIO.get_namespace().argsByEvent, {
'emit_response': (),
})
def test_emit_with_payload(self):
'Emit with payload'
self.socketIO.define(Namespace)
self.socketIO.emit('emit_with_payload', PAYLOAD)
self.socketIO.wait(0.1)
self.assertEqual(self.socketIO.get_namespace().argsByEvent, {
'emit_with_payload_response': (PAYLOAD,),
})
def test_emit_with_multiple_payloads(self):
'Emit with multiple payloads'
self.socketIO.define(Namespace)
self.socketIO.emit('emit_with_multiple_payloads', PAYLOAD, PAYLOAD)
self.socketIO.wait(0.1)
self.assertEqual(self.socketIO.get_namespace().argsByEvent, {
'emit_with_multiple_payloads_response': (PAYLOAD, PAYLOAD),
})
def test_emit_with_callback(self):
#.........这里部分代码省略.........