From f09fa0cbf5545b36bbff4b9b645748625e95c64a Mon Sep 17 00:00:00 2001 From: Manuel Vergara Date: Thu, 11 Jan 2024 21:43:05 +0100 Subject: [PATCH] =?UTF-8?q?Update=20Python=20Ofensivo=20-=20Pruebas=20de?= =?UTF-8?q?=20conexi=C3=B3n=20UDP=20con=20la=20librer=C3=ADa=20socket?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../03_socket/client.py | 18 +++++++++++++++ .../03_socket/server.py | 23 +++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 python-ofensivo/07_conexiones_red_protocolos/03_socket/client.py create mode 100644 python-ofensivo/07_conexiones_red_protocolos/03_socket/server.py diff --git a/python-ofensivo/07_conexiones_red_protocolos/03_socket/client.py b/python-ofensivo/07_conexiones_red_protocolos/03_socket/client.py new file mode 100644 index 0000000..af2d1dd --- /dev/null +++ b/python-ofensivo/07_conexiones_red_protocolos/03_socket/client.py @@ -0,0 +1,18 @@ +#!/usr/bin/env python3 + +import socket + + +def start_udp_client(): + + host = 'localhost' + port = 1234 + + with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as s: + + msg = 'Hola Servidor UDP! Se está tensando para pasar tildes'.encode( + 'utf-8') + s.sendto(msg, (host, port)) + + +start_udp_client() diff --git a/python-ofensivo/07_conexiones_red_protocolos/03_socket/server.py b/python-ofensivo/07_conexiones_red_protocolos/03_socket/server.py new file mode 100644 index 0000000..11da2b7 --- /dev/null +++ b/python-ofensivo/07_conexiones_red_protocolos/03_socket/server.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python3 +""" +Servidor UDP +""" + + +import socket + +def start_udp_server(): + + host = "localhost" + port = 1234 + + with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as s: + s.bind((host, port)) + print(f"Servidor UDP escuchando en {host}:{port}") + + while True: + data, addr = s.recvfrom(1024) + print(f"Recibido {data.decode()} de {addr}") + s.sendto(data, addr) + +start_udp_server() \ No newline at end of file