近期Python
2022/7/10 14:24:02
本文主要是介绍近期Python,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
import socket def main(): client=socket.socket() client.connect(("127.0.0.1",8081)) while True: inputs=input(">>>").strip() client.send(len(inputs).to_bytes(1,byteorder="little",signed=False)) client.send(inputs.encode()) recvs=client.recv(1025) print(recvs.decode(encoding="utf-8")) if __name__=="__main__": main()
import socket def process(conn,address): print("client connect :",conn,address) try: while True: data=conn.recv(1024) if len(data)==0: break else: print(data.decode()) conn.send(data) except ConnectionResetError as e: print(e) def main(): server=socket.socket() server.bind(("127.0.0.1",8081)) server.listen(5) while True: conn,address=server.accept() process(conn,address) if __name__=="__main__": main()
这篇关于近期Python的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-26Python基础编程
- 2024-11-25Python编程基础:变量与类型
- 2024-11-25Python编程基础与实践
- 2024-11-24Python编程基础详解
- 2024-11-21Python编程基础教程
- 2024-11-20Python编程基础与实践
- 2024-11-20Python编程基础与高级应用
- 2024-11-19Python 基础编程教程
- 2024-11-19Python基础入门教程
- 2024-11-17在FastAPI项目中添加一个生产级别的数据库——本地环境搭建指南