forked from evanw/socket.io-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests.py
More file actions
41 lines (34 loc) · 1.21 KB
/
tests.py
File metadata and controls
41 lines (34 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from SimpleHTTPServer import SimpleHTTPRequestHandler
from SocketServer import TCPServer
import socket_io as io
class Server(io.Server):
def on_connect(self, client):
client.name = None
def on_message(self, client, message):
command, value = message.split(':', 1)
print 'got message', command, 'starting with', '"%s"' % value[:30]
if command == 'setname':
client.name = value
elif command == 'broadcast':
self.broadcast(value)
elif command == 'echo':
client.send(value)
elif command == 'send':
name, data = value.split(':', 1)
for client in self.clients.values():
if client.name == name:
client.send(data)
def on_disconnect(self, client):
pass
def run_server():
from SimpleHTTPServer import SimpleHTTPRequestHandler
from SocketServer import TCPServer
class NiceServer(TCPServer):
allow_reuse_address = True
NiceServer(('', 8000), SimpleHTTPRequestHandler).serve_forever()
import threading
t = threading.Thread(target=run_server)
t.daemon = True
t.start()
print '\nopen http://localhost:8000/tests.html to run tests\n'
Server().listen(5000)