Allow connect to local or remote server
This commit is contained in:
parent
fcb2a948d8
commit
3e95e96f78
@ -10,7 +10,8 @@ from wcferry import Wcf
|
|||||||
|
|
||||||
def main():
|
def main():
|
||||||
logging.info("Start demo...")
|
logging.info("Start demo...")
|
||||||
wcf = Wcf()
|
wcf = Wcf() # 默认连接本地服务
|
||||||
|
# wcf = Wcf("IP:10086") # 连接远端服务
|
||||||
|
|
||||||
def handler(sig, frame):
|
def handler(sig, frame):
|
||||||
wcf.cleanup()
|
wcf.cleanup()
|
||||||
|
@ -18,7 +18,7 @@ sys.path.insert(0, WCF_ROOT)
|
|||||||
import wcf_pb2 # noqa
|
import wcf_pb2 # noqa
|
||||||
import wcf_pb2_grpc # noqa
|
import wcf_pb2_grpc # noqa
|
||||||
|
|
||||||
__version__ = "v3.7.0.30.11"
|
__version__ = "v3.7.0.30.12"
|
||||||
|
|
||||||
|
|
||||||
class Wcf():
|
class Wcf():
|
||||||
@ -58,13 +58,17 @@ class Wcf():
|
|||||||
"""是否文本消息"""
|
"""是否文本消息"""
|
||||||
return self.type == 1
|
return self.type == 1
|
||||||
|
|
||||||
def __init__(self, host_port: str = "localhost:10086") -> None:
|
def __init__(self, host_port: str = None) -> None:
|
||||||
|
self._local_host = False
|
||||||
|
self._is_running = False
|
||||||
self._enable_recv_msg = False
|
self._enable_recv_msg = False
|
||||||
self.LOG = logging.getLogger("WCF")
|
self.LOG = logging.getLogger("WCF")
|
||||||
self._sdk = ctypes.cdll.LoadLibrary(f"{WCF_ROOT}/sdk.dll")
|
if host_port is None:
|
||||||
if self._sdk.WxInitSDK() != 0:
|
self._local_host = True
|
||||||
self.LOG.error("初始化失败!")
|
host_port = "127.0.0.1:10086"
|
||||||
return
|
self._sdk = ctypes.cdll.LoadLibrary(f"{WCF_ROOT}/sdk.dll")
|
||||||
|
if self._sdk.WxInitSDK() != 0:
|
||||||
|
self.LOG.error("初始化失败!")
|
||||||
|
|
||||||
self._channel = grpc.insecure_channel(host_port)
|
self._channel = grpc.insecure_channel(host_port)
|
||||||
self._stub = wcf_pb2_grpc.WcfStub(self._channel)
|
self._stub = wcf_pb2_grpc.WcfStub(self._channel)
|
||||||
@ -84,10 +88,11 @@ class Wcf():
|
|||||||
|
|
||||||
self.disable_recv_msg()
|
self.disable_recv_msg()
|
||||||
self._channel.close()
|
self._channel.close()
|
||||||
self._sdk.WxDestroySDK()
|
if self._local_host:
|
||||||
handle = self._sdk._handle
|
self._sdk.WxDestroySDK()
|
||||||
del self._sdk
|
handle = self._sdk._handle
|
||||||
ctypes.windll.kernel32.FreeLibrary(handle)
|
del self._sdk
|
||||||
|
ctypes.windll.kernel32.FreeLibrary(handle)
|
||||||
self._is_running = False
|
self._is_running = False
|
||||||
|
|
||||||
def keep_running(self):
|
def keep_running(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user