From 6a0d3ff5832e57ee1b1374d086f24b3c1679b332 Mon Sep 17 00:00:00 2001 From: Administrator <admin@example.com> Date: 星期五, 05 九月 2025 18:22:24 +0800 Subject: [PATCH] bug修复/降低测撤单率 --- huaxin_client/socket_util.py | 21 +++++++++++++++++++++ 1 files changed, 21 insertions(+), 0 deletions(-) diff --git a/huaxin_client/socket_util.py b/huaxin_client/socket_util.py index f14cdd6..8347e33 100644 --- a/huaxin_client/socket_util.py +++ b/huaxin_client/socket_util.py @@ -5,6 +5,7 @@ # 娣诲姞鏁版嵁澶� import json +import socket from huaxin_client import crypt @@ -73,3 +74,23 @@ return True else: return False + + +def is_port_open(host, port, timeout=1): + try: + # 鍒涘缓涓�涓猻ocket瀵硅薄 + s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + # 璁剧疆瓒呮椂鏃堕棿涓�1绉掗挓 + s.settimeout(timeout) + # 灏濊瘯杩炴帴鍒版寚瀹氱殑涓绘満鍜岀鍙� + s.connect((host, port)) + # 濡傛灉杩炴帴鎴愬姛锛屽垯绔彛鏄墦寮�鐨� + s.close() + return True + except socket.error: + # 濡傛灉杩炴帴鍑虹幇寮傚父锛屽垯绔彛鏄叧闂殑 + return False + + +if __name__ == "__main__": + print(is_port_open("127.0.0.1",8080)) \ No newline at end of file -- Gitblit v1.8.0