server:
import json
import socket
server
= socket
.socket
(socket
.AF_INET
,socket
.SOCK_STREAM
)
server
.bind
(('10.0.13.134',12360))
server
.listen
(5)
while True:
conn
,addr
= server
.accept
()
print(conn
,addr
)
while True:
try:
js_string
= conn
.recv
(512)
js_string
=js_string
.decode
('utf-8', 'ignore')
print('recive:',js_string
)
if not len(js_string
) :
break
except ConnectionResetError
as e
:
print('关闭了正在占线的链接!')
break
client:
import time
import json
import socket
client
= socket
.socket
(socket
.AF_INET
,socket
.SOCK_STREAM
)
client
.connect
(('10.0.13.134', 12360))
DATA
={
'Time':None,
'bbox':None,
'confidence':None,
'label':None,
'shape':None,
'auxl':None,
}
while True:
DATA
['Time']=time
.time
()
DATA
['bbox']=[[0.1,0.2,0.3,0.9]]
DATA
['confidence']=[0.9]
DATA
['label']='smoke'
DATA
['shape']=(1080,1920)
json_string
=json
.dumps
(DATA
)
client
.send
(bytes(json_string
,encoding
='utf-8'))
client
.send
(bytes("new_start",encoding
='utf-8'))
client
.close
()
转载请注明原文地址:https://tech.qufami.com/read-16998.html