18 lines
506 B
Python
Executable File
18 lines
506 B
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
import socket
|
|
import struct
|
|
|
|
def start_udp_server():
|
|
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
|
sock.bind(('0.0.0.0', 10101))
|
|
print("Serveur UDP démarré sur le port 10101")
|
|
|
|
while True:
|
|
data, addr = sock.recvfrom(1024)
|
|
if len(data) == 2:
|
|
packet_num, instruction = struct.unpack('BB', data)
|
|
print(f"Reçu: packet_number={packet_num}, instruction={instruction}")
|
|
|
|
if __name__ == '__main__':
|
|
start_udp_server() |