piffy icon

TCP Client (Python)

piffy | PRO | 08/10/22 01:48:40 PM UTC | 0 ⭐ | 1090 👁️ | Never ⏰ | []
Python |

300 B

|

None

|

0 👍

/

0 👎

import socket
 
#Con il costrutto with il socket si chiude automaticamente.
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
    s.connect(('locahlhost', 6666))
    messaggio=input('-> ')
    s.sendall(messaggio.encode())
    data = s.recv(len(messaggio))
 
print(f"Ricevuto {data.decode()}")

Comments