import socket
# Creazione del socket UDP
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
indirizzo_server = ('localhost', 6666) # Binding
print ('Avvio server sulla %s alla porta %s' % indirizzo_server)
sock.bind(indirizzo_server)
while True:
print ('In attesa del messaggio')
dati, indirizzo = sock.recvfrom(4096)
print ('Ricevuti %s byte da %s' % (len(dati), indirizzo))
print (dati)
if dati:
sent = sock.sendto(dati, indirizzo)
print ('Rispediti %s byte a %s' % (sent, indirizzo))
Comments