practice_code/python/test/test.py

38 lines
1.3 KiB
Python
Raw Normal View History

import json
import multiprocessing
from multiprocessing.connection import Listener
import threading
class ProcessServer:
def __init__(self):
self.Process_port = 12321
self.Process_server = 'localhost'
self.Process_server_listener = Listener((self.Process_server, self.Process_port))
self.Process_client_link_dick = {}
Process_client_link_Thread = threading.Thread(target=self.Process_client_link)
Process_client_link_Thread.start()
def Process_client_link(self):
while True:
client_connect = self.Process_server_listener.accept()
print(type(client_connect))
client_process_recv = threading.Thread(target=self.Process_client_recv, args=(client_connect,))
client_process_recv.start()
def Process_client_recv(self, client_process_recv):
while True:
data_json = client_process_recv.recv()
data = json.loads(data_json)
print(data)
def Process_client_send(self, target, function, content):
connect = self.Process_client_link_dick[target]
data = {"target": target, "function": function, "content": content}
data_json = json.dumps(data)
connect.send(data_json)
def Process_client_pick(self):
pass