I know the threads at the theoretical level, I know there are two modules to use them, one is low level and the other high level, the first is threading and the second is thread, this I have seen in a wiki, after that I know that there are many methods but I do not know what to use for my purpose, I mean a local chat that can serve multiple clients, what I have now is a server that can only serve one client, if I connect with another client close the connection, the code is as follows I inform that I do not master object oriented programming very well therefore I appreciate that the solution is according to this style.
#servidor
import socket
host = "127.0.0.1"
port = 6666
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print ("Socket Created")
sock.bind((host, port))
print ("socket bind complete")
sock.listen(1)
print ("socket now listening")
while 1:
conn, addr = sock.accept()
try:
print('conexion con {}.'.format(addr))
conn.send("server: Hello client".encode('UTF-8'))
while True:
datos = conn.recv(4096)
if datos:
print('recibido: {}'.format(datos.decode('utf-8')))
else:
print("prueba")
break
finally:
conn.close()
#cliente
import socket
host = "127.0.0.1"
port = 6666
sock = socket.socket()
sock.connect((host, port))
datos = sock.recv(4096)
print (datos.decode('utf-8'))
while True:
message = input("envia un mensaje")
sock.send(message.encode('utf-8'))
if message == "quit":
break
print("bye")
sock.close()