You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
20 lines
556 B
20 lines
556 B
import socket
|
|
|
|
HOST = '127.0.0.1'
|
|
PORT = 2000
|
|
|
|
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
|
s.connect((HOST, PORT))
|
|
print('Conectado con éxito')
|
|
|
|
while True:
|
|
message = input("Enter a message (or 'exit' to quit): ")
|
|
if message.lower() == 'exit':
|
|
break
|
|
|
|
s.sendall(message.encode('utf-8'))
|
|
num_bytes_sent = len(message.encode('utf-8'))
|
|
print(f"Sent {num_bytes_sent} bytes")
|
|
|
|
data = s.recv(1024) # línea bloqueante
|
|
print('Recibido:', repr(data.decode('utf-8'))) |