1 Star 0 Fork 46

O_nly/qytang_Python

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
2016.1.16 线程服务器 thread-server 696 Bytes
一键复制 编辑 原始数据 按行查看 历史
现任明教教主-乾颐堂 提交于 2016-01-16 11:13 . new file
import time, _thread as thread
from socket import *
myHost = ''
myPort = 50007
sockobj = socket(AF_INET, SOCK_STREAM)
sockobj.bind((myHost, myPort))
sockobj.listen(5)
def now():
return time.ctime(time.time())
def handleClient(connection):
time.sleep(5)
while True:
data = connection.recv(1024)
if not data: break
reply = 'Echo=>%s at %s' % (data, now())
connection.send(reply.encode())
connection.close()
def dispatcher():
while True:
connection, address = sockobj.accept()
print('Server connected by', address, end = ' ')
print('at', now())
thread.start_new_thread(handleClient, (connection,))
if __name__ == '__main__':
dispatcher()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/scj0531/qytang_Python.git
git@gitee.com:scj0531/qytang_Python.git
scj0531
qytang_Python
qytang_Python
master

搜索帮助