-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathserver_tornado.py
More file actions
33 lines (25 loc) · 825 Bytes
/
server_tornado.py
File metadata and controls
33 lines (25 loc) · 825 Bytes
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from tornado.ioloop import IOLoop
from tornado.tcpserver import TCPServer
class EchoServer(TCPServer):
def handle_stream(self, stream, address):
def on_message(data):
stream.write_to_fd(data)
stream.read_until(b'\n', on_message)
stream.read_until(b'\n', on_message)
if __name__ == '__main__':
import sys
port = int(sys.argv[1]) if len(sys.argv) > 1 else 5000
print('Starting %s on %d' % ( __file__, port))
try:
server = EchoServer()
server.listen(port)
#server.bind(port)
#server.start(0)
IOLoop.instance().start()
except (KeyboardInterrupt, SystemExit):
print('Exiting...')
finally:
IOLoop.instance().stop()
print("exited cleanly")