一.
server.py
import socket
host="localhost"
port=
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.bind((host,port))
s.listen()
while():
sock,addr=s.accept()
print("got connection form ",sock.getpeername())
sock.send('Hello!')
data=sock.recv()
if not data:
print("no client")
else:
print(data)
输出
('got connection form ', ('127.0.0.1', ))
{"req": "add", "obj": "nav", "param": {"marker": "mark_name"}, "seq": }exitbye bye
client.py
import socket
import json
import time
host="localhost"
port=
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.connect((host,port))
data={"req":"add","obj":"nav","seq":,"param":{"marker":"mark_name"}}
j = json.dumps(data)
s.send(j) print("fff")
s.send('exit')
s.send('bye bye')
print("dddd")
#print(s.recv())
time.sleep()
s.close()
输出
fff
dddd