server.py
#coding:utf-8
import socket # 导入socket模块
s=socket.socket() # 初始化socket对象
s.bind(('127.0.0.1',1234)) # 绑定端口号为1234
s.listen(5) # 等待客户端连接
while True:
conn,addr=s.accept() #客户端连接后,得到connect和address
print('连接地址为',addr)
data=conn.recv(1024).decode()
conn.send(data.encode())
conn.close()
s.close()
client.py
#coding:utf-8
import socket
from socket import *
s=socket(AF_INET, SOCK_STREAM)
s.connect(('127.0.0.1',1234))
dictionary={'title':'title1','content':'content1'}
s.send(str(dictionary).encode())
clientrecieveData=s.recv(1024).decode()
print(clientrecieveData)
s.close()