forked from wilk/ExtJS-WebSocket
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
35 lines (26 loc) · 886 Bytes
/
server.py
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
#! /usr/bin/env python
from tornado import websocket
from tornado import web
from tornado import ioloop
import json
import sys
class EchoWebSocket (websocket.WebSocketHandler):
def open (self):
print 'WebSocket opened!'
def on_message (self, message):
self.write_message (message)
print 'He sais: ' + message
def on_close (self):
print 'WebSocket closed'
if __name__ == '__main__':
if (len (sys.argv) <= 1):
print 'Usage: $ python server.py <port1> <port2> <port3> ...'
print 'Example: $ python server.py 8888 9999 10000'
print 'Exit'
else:
app = [0]
[app.append (web.Application ([(r"/", EchoWebSocket)])) for i in range (1, len (sys.argv))]
[app[i].listen (int (sys.argv[i])) for i in range (1, len (sys.argv))]
for i in range (1, len (sys.argv)):
print 'Server listening at %d' % int (sys.argv[i])
ioloop.IOLoop.instance().start ()