From c0fb239118489d7f0db6041c18b5d27dfc5e2074 Mon Sep 17 00:00:00 2001 From: vicsash Date: Thu, 15 Feb 2024 22:59:17 +0100 Subject: [PATCH] Proyecto Cajero --- .idea/.gitignore | 8 +++++ .idea/ProjectCajero.iml | 10 ++++++ .../inspectionProfiles/profiles_settings.xml | 6 ++++ .idea/misc.xml | 7 ++++ .idea/modules.xml | 8 +++++ .idea/vcs.xml | 6 ++++ Cliente.py | 22 ++++++++++++ Cliente2.py | 22 ++++++++++++ Cliente3.py | 22 ++++++++++++ Cliente4.py | 22 ++++++++++++ Cliente5.py | 22 ++++++++++++ Cliente6.py | 22 ++++++++++++ ServidorCajero.py | 36 +++++++++++++++++++ 13 files changed, 213 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/ProjectCajero.iml create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 Cliente.py create mode 100644 Cliente2.py create mode 100644 Cliente3.py create mode 100644 Cliente4.py create mode 100644 Cliente5.py create mode 100644 Cliente6.py create mode 100644 ServidorCajero.py diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/ProjectCajero.iml b/.idea/ProjectCajero.iml new file mode 100644 index 0000000..7307346 --- /dev/null +++ b/.idea/ProjectCajero.iml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..4dcd2e3 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..29393eb --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Cliente.py b/Cliente.py new file mode 100644 index 0000000..53915f2 --- /dev/null +++ b/Cliente.py @@ -0,0 +1,22 @@ +import socket + +HOST = '192.168.50.166' +PORT = 2005 + +while True: + with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: + server_address = (HOST, PORT) + s.connect(server_address) + command = input("Entra comando (retirar o 'exit' para salir): ") + if command.lower() == 'exit': + break + elif command.lower() == 'retirar': + amount = input("Entera la cantidad de dinero: ") + message = f"{command} {amount}" + else: + print("Comando no reconocido") + print('Mandando {!r}'.format(message)) + s.sendall(message.encode('utf-8')) + print('Esperando la respuesta') + data = s.recv(1024) # línea bloqueante + print('recibido {!r} de {}'.format(data.decode('utf-8'), server_address)) \ No newline at end of file diff --git a/Cliente2.py b/Cliente2.py new file mode 100644 index 0000000..53915f2 --- /dev/null +++ b/Cliente2.py @@ -0,0 +1,22 @@ +import socket + +HOST = '192.168.50.166' +PORT = 2005 + +while True: + with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: + server_address = (HOST, PORT) + s.connect(server_address) + command = input("Entra comando (retirar o 'exit' para salir): ") + if command.lower() == 'exit': + break + elif command.lower() == 'retirar': + amount = input("Entera la cantidad de dinero: ") + message = f"{command} {amount}" + else: + print("Comando no reconocido") + print('Mandando {!r}'.format(message)) + s.sendall(message.encode('utf-8')) + print('Esperando la respuesta') + data = s.recv(1024) # línea bloqueante + print('recibido {!r} de {}'.format(data.decode('utf-8'), server_address)) \ No newline at end of file diff --git a/Cliente3.py b/Cliente3.py new file mode 100644 index 0000000..53915f2 --- /dev/null +++ b/Cliente3.py @@ -0,0 +1,22 @@ +import socket + +HOST = '192.168.50.166' +PORT = 2005 + +while True: + with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: + server_address = (HOST, PORT) + s.connect(server_address) + command = input("Entra comando (retirar o 'exit' para salir): ") + if command.lower() == 'exit': + break + elif command.lower() == 'retirar': + amount = input("Entera la cantidad de dinero: ") + message = f"{command} {amount}" + else: + print("Comando no reconocido") + print('Mandando {!r}'.format(message)) + s.sendall(message.encode('utf-8')) + print('Esperando la respuesta') + data = s.recv(1024) # línea bloqueante + print('recibido {!r} de {}'.format(data.decode('utf-8'), server_address)) \ No newline at end of file diff --git a/Cliente4.py b/Cliente4.py new file mode 100644 index 0000000..53915f2 --- /dev/null +++ b/Cliente4.py @@ -0,0 +1,22 @@ +import socket + +HOST = '192.168.50.166' +PORT = 2005 + +while True: + with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: + server_address = (HOST, PORT) + s.connect(server_address) + command = input("Entra comando (retirar o 'exit' para salir): ") + if command.lower() == 'exit': + break + elif command.lower() == 'retirar': + amount = input("Entera la cantidad de dinero: ") + message = f"{command} {amount}" + else: + print("Comando no reconocido") + print('Mandando {!r}'.format(message)) + s.sendall(message.encode('utf-8')) + print('Esperando la respuesta') + data = s.recv(1024) # línea bloqueante + print('recibido {!r} de {}'.format(data.decode('utf-8'), server_address)) \ No newline at end of file diff --git a/Cliente5.py b/Cliente5.py new file mode 100644 index 0000000..53915f2 --- /dev/null +++ b/Cliente5.py @@ -0,0 +1,22 @@ +import socket + +HOST = '192.168.50.166' +PORT = 2005 + +while True: + with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: + server_address = (HOST, PORT) + s.connect(server_address) + command = input("Entra comando (retirar o 'exit' para salir): ") + if command.lower() == 'exit': + break + elif command.lower() == 'retirar': + amount = input("Entera la cantidad de dinero: ") + message = f"{command} {amount}" + else: + print("Comando no reconocido") + print('Mandando {!r}'.format(message)) + s.sendall(message.encode('utf-8')) + print('Esperando la respuesta') + data = s.recv(1024) # línea bloqueante + print('recibido {!r} de {}'.format(data.decode('utf-8'), server_address)) \ No newline at end of file diff --git a/Cliente6.py b/Cliente6.py new file mode 100644 index 0000000..53915f2 --- /dev/null +++ b/Cliente6.py @@ -0,0 +1,22 @@ +import socket + +HOST = '192.168.50.166' +PORT = 2005 + +while True: + with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: + server_address = (HOST, PORT) + s.connect(server_address) + command = input("Entra comando (retirar o 'exit' para salir): ") + if command.lower() == 'exit': + break + elif command.lower() == 'retirar': + amount = input("Entera la cantidad de dinero: ") + message = f"{command} {amount}" + else: + print("Comando no reconocido") + print('Mandando {!r}'.format(message)) + s.sendall(message.encode('utf-8')) + print('Esperando la respuesta') + data = s.recv(1024) # línea bloqueante + print('recibido {!r} de {}'.format(data.decode('utf-8'), server_address)) \ No newline at end of file diff --git a/ServidorCajero.py b/ServidorCajero.py new file mode 100644 index 0000000..c6bddcd --- /dev/null +++ b/ServidorCajero.py @@ -0,0 +1,36 @@ +import socket + +HOST = '' +PORT = 2005 +MAX_CONNECTIONS = 2 +MAX_DINERO = 120000 +connections = 0 +#pip install six +with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: + s_addr = (HOST, PORT) + s.bind(s_addr) + s.listen(MAX_CONNECTIONS) + while True: + if connections >= MAX_CONNECTIONS: + print('Maximo de conexiones alcanzado, esperando a que se libere una conexion.') + continue + client_socket, addr = s.accept() + connections += 1 # Increment connections after the check + with client_socket: + while True: + datos = client_socket.recv(1024) + if not datos: + connections -= 1 + break + print('Cliente connectetado y datos enviados : {} bytes de {}'.format(len(datos), addr)) + command, amount = datos.decode('utf-8').split() + amount = int(amount) + if command.lower() == 'retirar': + print('retiro exitoso') + if amount <= MAX_DINERO: + MAX_DINERO -= amount + response = f"Retiro Existoso." + else: + response = "Saldo insuficiente por favor intente mas tarde." + client_socket.sendall(response.encode('utf-8')) + print('enviados {} bytes de vuelta a {}'.format(len(response), addr)) \ No newline at end of file