def callTo(self, data, addr): """ Calls a function and sends to a different address """ # If the address received is 127.0.0.1 then the server # and the node calling this are the same. Because we know this # is why that happens we can set the 127.0.0.1 to the callers ip if data["addr"][0] == "127.0.0.1": data["addr"][0] = addr[0] # Make it a tuple addr = tuple(data["addr"]) # Data will become the message to cryptRecv to it # Dosent need the address del data["addr"] self.log("callTo", addr) try: # recvfunc should give us the message and status message, status = self.cryptRecv(data, NO_DECRYPT, addr) except Exception as e: self.log("FAILED to cryptRecv", e) self.log("callTo sending to", addr) # If for some reson we dont want to send a reply if status != comms.NO_REPLY: # Send the properly formated message to the client comms.sendMessage(self.client.sock, message, status, addr) # In case the service that called is busy dont reply return "", comms.NO_REPLY
def sendMessage(text): ui.addStatus("Sending message") comms.sendMessage(text) mesg = message(text,sender=username) mesg.saveToFile() ui.addMessage(mesg) ui.updateMessageScreen()
def test_ListenRecvExit(self): server = ListenRecvExit() serverProcess, port = genericServer.StartServer(server) # Create the udp socket sock = comms.udp() # Send the message to the server comms.sendMessage(sock, 'test', comms.OK, (genericServer.ADDR, port)) # Receive a message response, serverAddr = sock.recvfrom(comms.RECV_SIZE) # Parse the response and return it reply, status = comms.parseMessage(response) # Stop the server serverProcess.terminate() # If the test errored self.assertEqual(EXIT_MESSAGE, reply, \ 'Server reply is not exit message {0}'.format(reply)) self.assertEqual(comms.EXIT, status, \ 'Server did not exit, status code {0}'.format(status))
def send(self, message, addr, status=comms.OK, \ waitResponse=True, useSocket=False): """ Sends a message to an address and port. Returns the response string as well as the status code. Usage: res, status = client.send("localhost", 10000, "test message") """ sock = self.sock if useSocket != False: sock = useSocket # Send the properly formated message to the client comms.sendMessage(sock, message, status, addr) # If we dont need to wait for a response return if waitResponse != True: return "", comms.OK # Receive a message response, serverAddr = sock.recvfrom(comms.RECV_SIZE) # Parse the response and return it return comms.parseMessage(response)