24 lines
729 B
Python
24 lines
729 B
Python
|
|
import socket
|
||
|
|
import json
|
||
|
|
import time
|
||
|
|
|
||
|
|
|
||
|
|
def receive_vdes_data():
|
||
|
|
HOST = 'localhost' # 模拟器运行的地址
|
||
|
|
PORT = 8082 # 模拟器监听的端口
|
||
|
|
|
||
|
|
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
||
|
|
s.connect((HOST, PORT))
|
||
|
|
print(f"已连接到VDES数据模拟器 {HOST}:{PORT}")
|
||
|
|
|
||
|
|
while True:
|
||
|
|
# 接收数据(阻塞直到有数据)
|
||
|
|
data = s.recv(65536) # 足够大的缓冲区
|
||
|
|
# if not data:
|
||
|
|
# break
|
||
|
|
if data:
|
||
|
|
ships_data = json.loads(data.decode('utf-8'))
|
||
|
|
print(f"收到 {len(ships_data)} 条船舶数据")
|
||
|
|
print(ships_data)
|
||
|
|
|
||
|
|
receive_vdes_data()
|