用Python语言给你解答下,仅供参考。"""
使用socket(TCP/IP)传递json数据(a list)
"""
import json, socket
# 客户端
await_data = ['Khalid K', "Boy"]
if __name__ == "__main__":
client = socket.socket()
client.connect_ex(("127.0.0.1", 9999))
serialize_data = bytes(json.dumps(await_data), encoding="utf-8")
client.send(serialize_data)import socket, json
if __name__ == "__main__":
# 服务器端
server = socket.socket()
server.bind(("127.0.0.1", 9999))
server.listen(5)
soc, adr = server.accept()
data = (soc.recv(1024)).decode('utf-8')
reverse_data = json.loads(data)
print(reverse_data)
输出结果: