服务端 :
import socket sk = socket.socket() sk.bind(("127.0.0.1", 8080)) sk.listen() conn, addr = sk.accept() conn.send(b"hello") msg = conn.recv(1024) print(msg) conn.close() # 关闭连接 sk.close() # 关闭整个服务
客户端:
import socket sk = socket.socket() sk.connect(("127.0.0.1", 8080)) msg = sk.recv(1024) print(msg) sk.send(b"byebye") sk.close()
标签:服务,socket,0.1,sk,msg,close,conn From: https://www.cnblogs.com/moon3496694/p/17139153.html