标签:for put pyc not author list char net else
服务端:
""" /etc/python3 @File : poll_test.py @Time : 2020/7/17 下午5:00 @Author : wangyongqi @Email : 92644827@qq.com @SOftware : PyCharm """ from socket import * from select import * from time import * from select import poll HOST=‘0.0.0.0‘ PORT=9548 ADDR=(HOST,PORT) tcp_socket=socket() tcp_socket.bind(ADDR) tcp_socket.listen(5) p=poll() p.register(tcp_socket,POLLIN) map={tcp_socket.fileno():tcp_socket,} print(tcp_socket.fileno()) print(len(map)) while True: events=p.poll() for fd,evnet in events: # for __ in map: if fd==tcp_socket.fileno(): connfd, addr = map[fd].accept() print("waiting for conect",addr) p.register(connfd, POLLIN | POLLOUT) map[connfd.fileno()]=connfd else: data=map[fd].recv(1024).decode() if not data: del map[fd] p.unregister(fd) map[fd].close() continue print(data) map[fd].send(b‘ok‘)
客户端:
""" /etc/python3 @File : tcp_conecter.py @Time : 2020/7/17 下午2:43 @Author : wangyongqi @Email : 92644827@qq.com @SOftware : PyCharm """ from socket import socket sockfd=socket() sockfd.connect((‘0.0.0.0‘,9548)) while True: sockfd.send(input(">>").encode())
标签:for put pyc not author list char net else
原文地址:https://www.cnblogs.com/yongqi-wang/p/13332590.html