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.
24 lines
563 B
24 lines
563 B
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) |