16 Star 45 Fork 46

现任明教教主-乾颐堂/qytang_Python

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
2016.1.15 fork-server-signal.py 772 Bytes
一键复制 编辑 原始数据 按行查看 历史
现任明教教主-乾颐堂 提交于 2016-01-15 10:32 . new file
import os, time, sys, signal
from socket import *
myHost = ''
myPort = 50007
sockobj = socket(AF_INET, SOCK_STREAM)
sockobj.bind((myHost, myPort))
sockobj.listen(5)
signal.signal(signal.SIGCHLD, signal.SIG_IGN)
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()
os._exit(0)
def dispatcher():
while True:
connection, address = sockobj.accept()
print('Server connected by', address, end = ' ')
print('at', now())
childPid = os.fork()
if childPid == 0:
handleClient(connection)
if __name__ == '__main__':
dispatcher()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/qytang/qytang_Python.git
[email protected]:qytang/qytang_Python.git
qytang
qytang_Python
qytang_Python
master

搜索帮助