From b7908f278dbb392ceab3e0c35257433eb41e6678 Mon Sep 17 00:00:00 2001 From: zhangsheng Date: Tue, 27 May 2025 09:57:59 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=88=B0=E8=BF=9C=E7=A8=8Bgi?= =?UTF-8?q?t?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 ++ server.py | 56 ------------------------------------------------------ 2 files changed, 2 insertions(+), 56 deletions(-) delete mode 100644 server.py diff --git a/.gitignore b/.gitignore index 2118c21..4fa5f48 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ build/ .idea/ dist/ +*.pyc +mainwindow - 副本.py diff --git a/server.py b/server.py deleted file mode 100644 index 164ac0d..0000000 --- a/server.py +++ /dev/null @@ -1,56 +0,0 @@ -import socket -import numpy as np -import time - -# 设置服务端IP和端口 -HOST = '0.0.0.0' # 监听所有网络接口 -PORT = 12345 # 端口号 - - -def generate_data(sample_rate=96000, duration=1): - """生成模拟的采样数据""" - t = np.linspace(0, duration, int(sample_rate * duration), endpoint=False) - # 使用正弦波生成模拟数据,可以替换为其他类型的数据 - data = np.sin(2 * np.pi * 1000 * t) # 1kHz 正弦波 - return data.astype(np.float32) - - -def start_server(): - """启动socket服务端""" - # 创建socket对象 - server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - server_socket.bind((HOST, PORT)) - server_socket.listen(1) - print(f"服务器启动,等待客户端连接...") - - # 等待客户端连接 - client_socket, client_address = server_socket.accept() - print(f"客户端 {client_address} 已连接") - - try: - while True: - # 生成96k采样的数据 - data = generate_data(sample_rate=96000, duration=1) # 生成 1 秒钟的采样数据 - # 将数据转换为字节流 - data_bytes = data.tobytes() - - # 发送数据 - client_socket.sendall(data_bytes) - print("发送数据给客户端...") - - - # 等待 1 秒后再发送下一组数据 - time.sleep(1) - - except Exception as e: - print(f"发生错误: {e}") - - finally: - # 关闭连接 - client_socket.close() - server_socket.close() - print("连接已关闭") - - -if __name__ == '__main__': - start_server()