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