diff --git a/Readme.md b/Readme.md new file mode 100644 index 0000000..7ce3535 --- /dev/null +++ b/Readme.md @@ -0,0 +1,13 @@ +Proyecto de simulacion de cajero automatico + +Este proyecto simula como funciona un cajero automatico, con opcion de retirar dinero. +Habia que conseguir varia cosas, que pueden conectar varios usuarios o mejor dicho clientes al servidor para retirar dinero y habia que limitar el numero maximo de clientes que pueden conectar al servidor. + +Encaso que no hay conecion libre no pueden conctar al 'cajero' y tienen sale mensaje que no hay conecion libre y se deconectal el cliente. En el Servidor +se puede ver cuantos clientes estan conectados y cuantos clientes desconectan del servidor. + +Segundo objetivo era que en caos que no hay suficiente dinero en el cajero, el cliente no puede retirar dinero y sale mensaje que no hay suficiente dinero en el cajero. + +Puude necesitar la instalacion de siguintes cosas: + + pip install six \ No newline at end of file diff --git a/ServidorCajero.py b/Servidor/ServidorCajero.py similarity index 97% rename from ServidorCajero.py rename to Servidor/ServidorCajero.py index ae86058..e6f44dd 100644 --- a/ServidorCajero.py +++ b/Servidor/ServidorCajero.py @@ -1,5 +1,4 @@ import socket -import sys import threading HOST = '' @@ -45,6 +44,7 @@ def handle_client(client_socket, addr): print(f"Saldo restante: {MAX_DINERO}") else: response = "Saldo insuficiente por favor intente mas tarde." + print("Saldo insuficiente para operacion.") client_socket.sendall(response.encode('utf-8')) elif command.lower() == 'exit': break diff --git a/Cliente.py b/clientes/Cliente.py similarity index 81% rename from Cliente.py rename to clientes/Cliente.py index 8714ded..2cab986 100644 --- a/Cliente.py +++ b/clientes/Cliente.py @@ -41,8 +41,13 @@ while True: elif command.lower() == 'retirar': amount = input("Entera la cantidad de dinero: ") message = f"{command} {amount}" + s.sendall(message.encode('utf-8')) + data = s.recv(1024) + if data.decode('utf-8') == "Saldo insuficiente por favor intente mas tarde.": + print("No hay suficientes fondos. Por favor intente más tarde.") + break else: print("Comando no reconocido") message = command - s.sendall(message.encode('utf-8')) + s.sendall(message.encode('utf-8')) break diff --git a/Cliente2.py b/clientes/Cliente2.py similarity index 81% rename from Cliente2.py rename to clientes/Cliente2.py index 8714ded..2cab986 100644 --- a/Cliente2.py +++ b/clientes/Cliente2.py @@ -41,8 +41,13 @@ while True: elif command.lower() == 'retirar': amount = input("Entera la cantidad de dinero: ") message = f"{command} {amount}" + s.sendall(message.encode('utf-8')) + data = s.recv(1024) + if data.decode('utf-8') == "Saldo insuficiente por favor intente mas tarde.": + print("No hay suficientes fondos. Por favor intente más tarde.") + break else: print("Comando no reconocido") message = command - s.sendall(message.encode('utf-8')) + s.sendall(message.encode('utf-8')) break diff --git a/Cliente3.py b/clientes/Cliente3.py similarity index 81% rename from Cliente3.py rename to clientes/Cliente3.py index 8714ded..2cab986 100644 --- a/Cliente3.py +++ b/clientes/Cliente3.py @@ -41,8 +41,13 @@ while True: elif command.lower() == 'retirar': amount = input("Entera la cantidad de dinero: ") message = f"{command} {amount}" + s.sendall(message.encode('utf-8')) + data = s.recv(1024) + if data.decode('utf-8') == "Saldo insuficiente por favor intente mas tarde.": + print("No hay suficientes fondos. Por favor intente más tarde.") + break else: print("Comando no reconocido") message = command - s.sendall(message.encode('utf-8')) + s.sendall(message.encode('utf-8')) break diff --git a/Cliente4.py b/clientes/Cliente4.py similarity index 81% rename from Cliente4.py rename to clientes/Cliente4.py index 8714ded..2cab986 100644 --- a/Cliente4.py +++ b/clientes/Cliente4.py @@ -41,8 +41,13 @@ while True: elif command.lower() == 'retirar': amount = input("Entera la cantidad de dinero: ") message = f"{command} {amount}" + s.sendall(message.encode('utf-8')) + data = s.recv(1024) + if data.decode('utf-8') == "Saldo insuficiente por favor intente mas tarde.": + print("No hay suficientes fondos. Por favor intente más tarde.") + break else: print("Comando no reconocido") message = command - s.sendall(message.encode('utf-8')) + s.sendall(message.encode('utf-8')) break