Curso-lenguaje-python/python-ofensivo/07_conexiones_red_protocolos/04_socket/client.py

28 lines
502 B
Python

#!/usr/bin/env python3
import socket
def start_client():
host = 'localhost'
port = 1234
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.connect((host, port))
while True:
msg = input("[+] Introduce un mensaje: ")
s.sendall(msg.encode('utf-8'))
if msg.strip() == 'bye':
break
data = s.recv(1024)
print(f"\n[+] Mensaje del servidor: {data.decode().strip()}")
start_client()