Présentation
- Pour envoyer de la donnée (datagramme UDP) il faut connaître l’adresse IP et le port UDP de la machine distante.
- Pour recevoir des messages, il faut « écouter » sur son port local.
https://www.hw-group.com/files/download/sw/version/hercules_3-2-8.exe
import socket
UDP_IP_DISTANT = "172.19.68.95"
UDP_PORT_DISTANT = 4023
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.sendto(b"Coucou!", (UDP_IP_DISTANT, UDP_PORT_DISTANT))
import socket
UDP_IP_LOCAL = "172.19.69.6"
UDP_PORT_LOCAL = 4023
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.bind((UDP_IP_LOCAL, UDP_PORT_LOCAL))
reponse = ''
while reponse !="x" :
data, addr = sock.recvfrom(1024) # buffer size is 1024 bytes
reponse = data.decode()
print("received message: %s" % reponse)
Régi par la licence Creative Commons: Licence d'attribution en partage identique 4.0