Server:
以tcp为例子
import socket
# 创建套接字(两种方式)
s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
with socket.socket() as s:
# 套接字绑定到地址
s.bind(('127.0.0.1',3000))address为元祖,(host,port)
#开始监听TCP传入连接
s.listen(backlog)
#进入----循环----,不断接收客户端的请求
conn,address = s.accept()
# 接收传来的数据,并发送给对方
conn.recv()
conn.sendall()
Clien
s = socket.socket(socket.AF_INET,socket.SOCK_STREAM) # 定义family和type
host = '127.0.0.1'
port = 3000
s.connect((host,port))
s.send(cmd)
data = s.receive(1024)