Пример #1
0
class WebSocketTest(TestCase):
	def setUp(self):
		self.server = WebSocketServer('0.0.0.0', 9888, echo_callback)
		self.server.start()

	def tearDown(self):
		self.server.stop()

	def test_server(self):
		client = WebSocketClient('127.0.0.1', self.server.port, '127.0.0.1:8000')
		message = 'I hope this works'
		client.send(message)
		self.failUnlessEqual(message, client.receive())
		message = 'Does it work twice?'
		client.send(message)
		self.failUnlessEqual(message, client.receive())
		message = unicode('Does unicode like work?')
		client.send(message)
		self.failUnlessEqual(message, client.receive())
		client2 = WebSocketClient('127.0.0.1', self.server.port, '127.0.0.1:8000')
		message = 'I hope this works'
		client2.send(message)
		self.failUnlessEqual(message, client2.receive())
		message = 'Does this still work twice?'
		client.send(message)
		self.failUnlessEqual(message, client.receive())
		message = ''.join([chr(i % 100) for i in range(10000)])
		client.send(message)
		received = client.receive()
		self.failUnlessEqual(message, received, 'The long message is not equal.  Received %s of %s bytes' % (len(received), len(message)))
		client.close()
		message = 'Perhaps it works after the first has closed?'
		client2.send(message)
		self.failUnlessEqual(message, client2.receive())
		client2.close()
Пример #2
0
	def setUp(self):
		self.server = WebSocketServer('0.0.0.0', 9888, echo_callback)
		self.server.start()