服务端程序:
import socket phone = socket.socket(socket.AF_INET,socket.SOCK_STREAM) phone.bind((‘192.168.0.101‘,8000)) phone.listen(5) print("---->") conn,addr = phone.accept() msg = conn.recv(1024) print("客户端发来的消息是:", msg) conn.send("hello,client".encode("utf-8")) conn.close() phone.close()
客户端程序:
import socket phone = socket.socket(socket.AF_INET,socket.SOCK_STREAM) phone.connect((‘192.168.0.101‘,8000)) phone.send(‘hello,sever‘.encode("utf-8")) data = phone.recv(1024) print(" 收到的服务端发来的消息:",data)
原文:https://www.cnblogs.com/weiweideboke/p/9093998.html