From db6bd7fb2b43e8b12f01f42edcda164b8162d95b Mon Sep 17 00:00:00 2001 From: fosanz Date: Fri, 19 Jan 2024 18:42:47 +0100 Subject: [PATCH] Initial commit --- .idea/.gitignore | 8 +++++ .idea/UDPNetworking.iml | 10 ++++++ .idea/inspectionProfiles/Project_Default.xml | 23 +++++++++++++ .../inspectionProfiles/profiles_settings.xml | 6 ++++ .idea/misc.xml | 7 ++++ .idea/modules.xml | 8 +++++ .idea/vcs.xml | 6 ++++ alexa/alexaClient.py | 32 +++++++++++++++++++ alexa/alexaServer.py | 24 ++++++++++++++ test/clientUDP.py | 19 +++++++++++ test/serverUDP.py | 16 ++++++++++ 11 files changed, 159 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/UDPNetworking.iml create mode 100644 .idea/inspectionProfiles/Project_Default.xml 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 alexa/alexaClient.py create mode 100644 alexa/alexaServer.py create mode 100644 test/clientUDP.py create mode 100644 test/serverUDP.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/UDPNetworking.iml b/.idea/UDPNetworking.iml new file mode 100644 index 0000000..2c80e12 --- /dev/null +++ b/.idea/UDPNetworking.iml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..8413d42 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,23 @@ + + + + \ 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..5693b6a --- /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..dfac743 --- /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/alexa/alexaClient.py b/alexa/alexaClient.py new file mode 100644 index 0000000..55ed74f --- /dev/null +++ b/alexa/alexaClient.py @@ -0,0 +1,32 @@ +import socket + +HOST = '192.168.50.106' +PORT = 2000 + +with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as s: + s_addr = (HOST, PORT) + server_address = (s_addr) + # 1 para español, 2 para ingles, 3 para aleman + + while True: + idioma = input("Ingrese el idioma: ") + if idioma == "español": + message = b"1" + break + elif idioma == "ingles": + message = b"2" + break + elif idioma == "aleman": + message = b"3" + break + else: + print("Ingrese un idioma valido") + + # enviar + print('Enviando {}'.format(message)) + sent = s.sendto(message, server_address) + + # recibir + print('Esperando por la respuesta') + data, server = s.recvfrom(1024) # línea bloqueante + print('Recibido: {}'.format(data)) diff --git a/alexa/alexaServer.py b/alexa/alexaServer.py new file mode 100644 index 0000000..6b849f3 --- /dev/null +++ b/alexa/alexaServer.py @@ -0,0 +1,24 @@ +import socket +HOST = '' +PORT = 2000 +with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as s: + s_addr = (HOST, PORT) + s.bind(s_addr) + while True: + #recibir + datos, addr = s.recvfrom(1024) #línea bloqueante + print('recibidos {} bytes de {}'.format(len(datos), addr)) + print(datos) + #enviar + if datos: + + if datos == b"1": + s.sendto(b"hola", addr) + elif datos == b"2": + s.sendto(b"hello", addr) + + elif datos == b"3": + s.sendto(b"hallo", addr) + + else: + s.sendto(b"Lenguaje no reconocido", addr) \ No newline at end of file diff --git a/test/clientUDP.py b/test/clientUDP.py new file mode 100644 index 0000000..f0ad514 --- /dev/null +++ b/test/clientUDP.py @@ -0,0 +1,19 @@ +import socket + +HOST = '192.168.50.106' +PORT = 2000 + +with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as s: + s_addr = (HOST, PORT) + server_address = (s_addr) + cadena = input("Por favor, introduce una cadena: ") + message = bytes(cadena, 'utf-8') + + # enviar + print('Enviando {!r}'.format(message)) + sent = s.sendto(message, server_address) + + # recibir + print('Esperando por la respuesta') + data, server = s.recvfrom(1024) #línea bloqueante + print('recibidos {!r}'.format(data)) \ No newline at end of file diff --git a/test/serverUDP.py b/test/serverUDP.py new file mode 100644 index 0000000..0af9106 --- /dev/null +++ b/test/serverUDP.py @@ -0,0 +1,16 @@ +import socket + +HOST = '' +PORT = 2000 + +with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as s: + s_addr = (HOST, PORT) + s.bind(s_addr) + while True: + datos, addr = s.recvfrom(1024) + print("recibidos {} bytes de {}".format(len(datos), addr)) + print(datos) + + if datos: + sent = s.sendto(b"Saludos desde el servidor UDP", addr) + print('enviados {} bytes a {}'.format(sent, addr)) \ No newline at end of file