You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
21 lines
570 B
21 lines
570 B
8 months ago
|
import socket
|
||
|
|
||
|
HOST = '192.168.50.102'
|
||
|
PORT = 3333
|
||
|
|
||
|
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 (en formato eco y en mayúsculas)
|
||
|
if datos:
|
||
|
datos_upper = datos.upper()
|
||
|
sent = s.sendto(datos_upper, addr)
|
||
|
print('Enviados {} bytes de vuelta a {}'.format(sent, addr))
|