def send(self, address, msg): ''' Send a message to a given address, where address is a numerical IP in network byte order. ''' request = { 'action': 'push', 'method': 'tx', 'parameters': [int(address), int(14450), ''.join([self.sdc_encode_str(msg)])] } request = json.dumps(request) # We have automatic Python garbage collection from SWIG request = orsoqs.create_msg(request, len(request) + 1) # send_msg() sends our message and returns a response message # str() creates a copy of the response message string response = orsoqs.send_msg(self.osocket, request).str() response = json.loads(response) if 'error' in response and response['error'] == True: return False elif 'result' in response and response['result'] == True: return True else: return False
def check_con_request(endpoint): ''' Check our request type connection. ''' listenThread = multiprocessing.Process(target=zsocket_listen, args=(endpoint, dataToRequest, dataToReply)) listenThread.daemon = True listenThread.start() orclient = orsoqs.create_client() orsocket = orsoqs.connect(orclient, endpoint, orsoqs.CON_REQUEST) msg = orsoqs.create_msg(dataToRequest, len(dataToRequest)) rmsg = orsoqs.send_msg(orsocket, msg) assert rmsg.str() == dataToReply orsoqs.delete_msg(msg) orsoqs.delete_msg(rmsg) orsoqs.disconnect(orsocket) orsoqs.delete_client(orclient) listenThread.join()