显示端代码:
import socket
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import numpy as np
# UDP setup
udp_ip = '0.0.0.0' # Listen on all network interfaces
udp_port = 12345
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.bind((udp_ip, udp_port))
# Plot setup
# fig, ax = plt.subplots()
# xdata, ydata = [], []
# ln, = plt.plot([], [], 'r-')
# def init():
# ax.set_xlim(0, 100) # Adjust x-axis range as needed
# ax.set_ylim(-1, 1) # Adjust y-axis range as needed
# return ln,
# def update(frame):
# # Receive data
# global xdata, ydata
# data, _ = sock.recvfrom(1024)
# #print(data)
# signal = np.frombuffer(data, dtype=np.float32) #