Advertisement
piffy

UDP Server (Python)

Aug 10th, 2022
788
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.54 KB | None | 0 0
  1. import socket
  2.  
  3. # Creazione del socket UDP
  4. sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  5. indirizzo_server = ('localhost', 6666) # Binding
  6. print ('Avvio server sulla  %s alla porta  %s' % indirizzo_server)
  7. sock.bind(indirizzo_server)
  8.  
  9. while True:
  10.     print ('In attesa del messaggio')
  11.     dati, indirizzo = sock.recvfrom(4096)
  12.  
  13.     print ('Ricevuti %s byte da %s' % (len(dati), indirizzo))
  14.     print (dati)
  15.  
  16.     if dati:
  17.         sent = sock.sendto(dati, indirizzo)
  18.         print ('Rispediti %s byte a %s' % (sent, indirizzo))
  19.  
  20.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement