piffy icon

UDP Server (Python)

piffy | PRO | 08/10/22 02:30:40 PM UTC | 0 ⭐ | 1166 👁️ | Never ⏰ | []
Python |

540 B

|

None

|

0 👍

/

0 👎

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