2018-04-27 00:00:22 +08:00
|
|
|
"""
|
|
|
|
套接字 - 基于TCP协议创建时间服务器
|
|
|
|
|
|
|
|
Version: 0.1
|
|
|
|
Author: 骆昊
|
|
|
|
Date: 2018-03-22
|
|
|
|
"""
|
|
|
|
|
|
|
|
from socket import *
|
|
|
|
from time import *
|
|
|
|
|
|
|
|
server = socket(AF_INET, SOCK_STREAM)
|
|
|
|
server.bind(('localhost', 6789))
|
|
|
|
server.listen()
|
|
|
|
print('服务器已经启动正在监听客户端连接.')
|
|
|
|
while True:
|
2019-05-03 21:17:36 +08:00
|
|
|
client, addr = server.accept()
|
|
|
|
print('客户端%s:%d连接成功.' % (addr[0], addr[1]))
|
|
|
|
currtime = localtime(time())
|
|
|
|
timestr = strftime('%Y-%m-%d %H:%M:%S', currtime)
|
|
|
|
client.send(timestr.encode('utf-8'))
|
|
|
|
client.close()
|
2018-04-27 00:00:22 +08:00
|
|
|
server.close()
|