Advertisement
piffy

UDP Client (Python)

Aug 10th, 2022
801
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.43 KB | None | 0 0
  1. sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  2.  
  3. indirizzo_server = ('localhost', 6666)
  4. messaggio = 'Ecco il messaggio.'
  5. try:
  6.  
  7.     # Invio dati
  8.     print ('Invio messaggio')
  9.     sent = sock.sendto(messaggio, indirizzo_server)
  10.  
  11.     # Ricezione delle replica
  12.     print ('In attesa...')
  13.     dati, server = sock.recvfrom(4096)
  14.     print ('ricevuto: "%s"' % dati)
  15.  
  16. finally:
  17.     print ('chiusura socket')
  18.     sock.close(
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement