def message_handler(conn, addr): raw_data = conn.recv(1024) data = protocolUtils.MessageHandler(raw_data).message_loads() server_interface = switch_operations(data[1]) result = protocolUtils.MessageBuilder(server_interface[0], server_interface[1], False).message_builder() conn.send(result.encode())
def handle(self): server_prop = self.request.recv(1024).decode("utf-8") server_prop = self.get_server(server_prop) if server_prop: builder_instance = protocolUtils.MessageBuilder( server_prop[0], server_prop[1], True) self.request.send(builder_instance.message_builder().encode()) else: error = "Error: Operation doesnt exists" self.request.send(error.encode())
def main(): try: num1 = input("Insert a number: ") num2 = input("Insert a number: ") op = input("Insert the operation that you wants: ") message_builder = protocolUtils.MessageBuilder(num1, num2, op) function_op = switch_operations(message_builder.operation) op1, op2 = message_builder.get_operands() print("The result are: ", function_op(op1, op2)) except client.Fault as e: print(e)
def main(): try: num1 = input("Insert a number: ") num2 = input("Insert a number: ") op = input("Insert the operation that you wants: ") message_builder = protocolUtils.MessageBuilder(num1, num2, op) function_op = protocolUtils.ClientThread(server_of_names.get_server(message_builder.operation)) function_op.start() op1, op2 = message_builder.get_operands() print("The result are: ", function_op.call_function(op1, op2)) except client.Fault as e: print(e)
def main(): try: num1 = input("Insert a number: ") num2 = input("Insert a number: ") op = input("Insert the operation that you wants: ") message_builder = protocolUtils.MessageBuilder(num1, num2, op) # Get the absolute URL to do the connection directly server_op = names_resolver_server.get_operation_server(message_builder.operation) # Do the connection server_op = client.ServerProxy(server_op) op1, op2 = message_builder.get_operands() print("The result are: ", server_op.function(op1, op2)) except client.Fault: print("Error: The operation is not supported")
def main(): socket_instance = socket.socket() socket_instance.connect((protocolUtils.host, protocolUtils.port)) num1 = input("Ingrese un numero: ") num2 = input("Ingrese un numero: ") op = input("Ingrese la operacion a realizar: ") message_builder = protocolUtils.MessageBuilder(num1, num2, op) socket_instance.send(message_builder.operation.encode()) server = protocolUtils.MessageHandler( socket_instance.recv(1024)).message_loads() server_host, server_port = server[0], int(server[2]) # Close the actual session to start the new with the server of the operation socket_instance.close() socket_instance = socket.socket() socket_instance.connect((server_host, server_port)) socket_instance.send(message_builder.message_builder().encode()) result = socket_instance.recv(1024).decode() print("Result: ", result)
import socket import lib.ProtocolUtils as protocolUtils if __name__ == "__main__": socket_instance = socket.socket(socket.AF_INET, socket.SOCK_STREAM) socket_instance.connect(("localhost", 9999)) num1 = input("Ingrese un numero: ") num2 = input("Ingrese un numero: ") op = input("Ingrese la operacion a realizar: ") message_builder = protocolUtils.MessageBuilder(num1, num2, op) socket_instance.send(message_builder.message_builder().encode()) server_interface = protocolUtils.MessageHandler( socket_instance.recv(1024)).message_loads() server_instance = socket.socket(socket.AF_INET, socket.SOCK_STREAM) server_instance.connect((server_interface[0], int(server_interface[2]))) server_instance.send(message_builder.message_builder().encode()) result = server_instance.recv(1024) print("Resultado de la operacion fue ", result.decode("utf-8")) socket_instance.close()