服务端
import socket
sever=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
sever.bind(('127.0.0.1',8083))
sever.listen(5)
conn,client_addr=sever.accept()
data=conn.recv(1024)
if data == 'q':
conn.close()
res=bytes((eval(data)))
conn.send(res)
客户端
import socket
client=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
client.connect(('127.0.0.1',8083))
cmd='2+3'
client.send(cmd.encode('utf8'))
res=client.recv(1024)
print('=====',res.decode('utf8'))
client.close()