标签:AC display 循环 col cep inpu closed str 服务
import socket #from socket import * ip_port=(‘127.0.0.1‘,8000) back_log=5 buffer_size=1024 tcp_server=socket.socket(socket.AF_INET,socket.SOCK_STREAM) tcp_server.bind(ip_port) tcp_server.listen(back_log) print(‘服务端开始运行!‘) conn,addr=tcp_server.accept() print(‘双向连接:‘,conn) print(‘客户端地址:‘,addr) while True: data=conn.recv(buffer_size) print(‘来自客户端的消息:‘,data.decode(‘utf-8‘)) msg=input(‘服务端输入>>>:‘) conn.send(msg.encode(‘utf-8‘)) conn.close() tcp_server.close()
import socket #from socket import * ip_port=(‘127.0.0.1‘,8000) buffer_size=1024 tcp_client=socket.socket(socket.AF_INET,socket.SOCK_STREAM) tcp_client.connect(ip_port) while True: msg=input(‘客户端输入>>>:‘).strip() tcp_client.send(msg.encode(‘utf-8‘)) print(‘客户端已经发送消息!‘) data=tcp_client.recv(buffer_size) print(‘来自服务端信息:‘,data.decode(‘utf-8‘)) tcp_client.close()
标签:AC display 循环 col cep inpu closed str 服务
原文地址:https://www.cnblogs.com/benchdog/p/9129868.html