| | |
| | | |
| | | SERVER_HOST = '43.138.167.68' |
| | | SERVER_PORT = 10008 |
| | | SERVER_PUSH_PORT = 10009 |
| | | |
| | | |
| | | def request(data_json, host=SERVER_HOST, port=SERVER_PORT): |
| | | if type(data_json) == set: |
| | | data_json = list(data_json) |
| | | data_bytes = socket_util.load_header(json.dumps(data_json).encode('utf-8')) |
| | | sk = socket_util.create_socket(host, port) |
| | | try: |
| | | sk.sendall(data_bytes) |
| | | result_str, header_str = socket_util.recv_data(sk) |
| | | result_json = json.loads(result_str) |
| | | if result_json["code"] != 0: |
| | | raise Exception(result_json["msg"]) |
| | | return result_json.get("data") |
| | | finally: |
| | | sk.close() |
| | | |
| | | |
| | | def push(data_json, host=SERVER_HOST, port=SERVER_PUSH_PORT): |
| | | data_bytes = socket_util.load_header(json.dumps(data_json).encode('utf-8')) |
| | | sk = socket_util.create_socket(host, port) |
| | | try: |
| | |
| | | |
| | | # ------------------------------消息推送------------------------------------ |
| | | def load_push_msg(data): |
| | | fdata = {"type": "push_msg", "data": {"ctype": "push_msg", "data": data}} |
| | | fdata = {"type": "push_msg", "data": data} |
| | | return fdata |
| | | |
| | | |