Python-100-Days/Day01-15/code/Day14/socket5.py

22 lines
479 B
Python
Raw Normal View History

2018-04-27 00:00:22 +08:00
"""
使用socketserver模块创建时间服务器
Version: 0.1
Author: 骆昊
Date: 2018-03-22
"""
from socketserver import TCPServer, StreamRequestHandler
from time import *
class EchoRequestHandler(StreamRequestHandler):
2019-05-03 21:17:36 +08:00
def handle(self):
currtime = localtime(time())
timestr = strftime('%Y-%m-%d %H:%M:%S', currtime)
self.wfile.write(timestr.encode('utf-8'))
2018-04-27 00:00:22 +08:00
server = TCPServer(('localhost', 6789), EchoRequestHandler)
server.serve_forever()