Aug-26-2019, 12:52 AM
Hi guys. I have the following code (in Python 3.7.3):
################################################################################################### ### Librerias ### ################# import socket import threading import sys ################################################################################################### ### Servidor ### ################ class Server: sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) connections = [] def __init__(self): self.sock.bind(('0.0.0.0', 10000)) self.sock.listen(1) def handler(self,c,a): while True: data = c.recv(1024) for connection in self.connections: connection.send(data) if not data: print(str(a[0]) + ':' + str(a[1]), "Desconectado") self.connections.remove(c) c.close() break def run(self): while True: c,a = self.sock.accept() cThread = threading.Thread(target=self.handler, args=(c,a)) cThread.daemon = True cThread.start() self.connections.append(c) print(str(a[0]) + ':' + str(a[1]), "Conectado") ################################################################################################### ### Cliente ### ############### class Client: sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) def sendMsg(self): while True: self.sock.send(bytes(input(""),'utf-8')) def __init__(self): self.sock.connect((address, 10000)) iThread = threading.Thread(target=self.sendMsg) iThread.daemon = True iThread.start() while True: data = self.sock.recv(1024) if not data: break print(data) ################################################################################################### ### Ejecucion ### ################# if (len(sys.argv) > 1): client = Client(sys.argv(1)) else: server = Server() server.run() ###################################################################################################The Server code runs OK:
[Image: TQetpLI.png]
But the Client code does not:
[Image: s9xKfIg.png]
I am following this Video Tutorial:
Thank you very much for your help.