class Main_class_dll():
def __init__(self):
dllName = "SessionConnector.dll"
dllABSPath = os.path.dirname(os.path.abspath(__file__)) + os.path.sep + dllName
self.dll = cdll.LoadLibrary(dllABSPath)
self.session_id=''
def int_create_(self):
self.dll.Init.restype = c_bool
sign = self.dll.Init()
def Create_Session(self,ip,port):
self.dll.CreateSession.argtypes=[c_char_p,c_char_p] #输入参数的格式
self.dll.CreateSession.restype = c_int; #输出参数的格式
self.session_id = self.dll.CreateSession(ip,port);
def send_recv(self,buf):
time.sleep(2)
self.dll.SendSessionMsg.restype = c_bool;
self.dll.SendSessionMsg.argtypes=[c_int,c_char_p,c_uint]
ret = self.dll.SendSessionMsg(self.session_id, buf, len(buf) + 1);
self.dll.RecvSessionMsg.argtypes=[c_int,c_char_p,c_uint,c_int]
self.dll.RecvSessionMsg.restype = c_bool;
recv_buf = create_string_buffer(1024);
ret = self.dll.RecvSessionMsg(self.session_id, recv_buf, 1024, 3000);
self.dll.DestroySession.restype = c_bool;
ret = self.dll.DestroySession(self.session_id);
return recv_buf.value
|