Update Python Ofensivo - Pruebas de conexión UDP con la librería socket

This commit is contained in:
Manuel Vergara 2024-01-11 21:43:05 +01:00
parent ec29b5cde0
commit f09fa0cbf5
2 changed files with 41 additions and 0 deletions

View File

@ -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()

View File

@ -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()