admin
2025-06-10 568c763084b926a6f2d632b7ac65b9ec8280752f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import json
import socket
 
import requests
 
import constant
from utils import socket_util
 
SOCKET_PORT = 11008
# B类
HTTP_PORT = 9004
 
 
# A类
# HTTP_PORT = 9005
 
 
def socket_request(data, host=constant.SERVER_HOST, port=SOCKET_PORT):
    client = socket.socket()  # 生成socket,连接server
    ip_port = (host, port)  # server地址和端口号(最好是10000以后)
    client.connect(ip_port)
    if type(data) != str:
        client.send(socket_util.load_header(json.dumps(data).encode("utf-8")))
    else:
        client.send(socket_util.load_header(data.encode("utf-8")))
    # 读取内容
    result, header = socket_util.recv_data(client)
    print("socket_request结果:", result)
    client.close()
    return result
 
 
def http_get(path):
    response = requests.get(f"http://{constant.SERVER_HOST}:{HTTP_PORT}{path}")
    if response.status_code == 200:
        return response.text
    return None