Well my problem is this:
We are starting to see the topic of sockets and I have these examples:
CLIENT:
import socket
host = "localhost"
port = 9999
socket1 = socket.socket()
socket1.connect((host, port))
try:
while(True):
cadena = input("Mensaje para enviar al servidor: ")
socket1.send(cadena.encode(encoding='utf-8'))
print("se ha enviado la cadena: ", cadena)
CadenaRecServidor = socket1.recv(1024).decode('utf-8')
print("El servidor responde: ", CadenaRecServidor)
except Exception as e:
print("error", e)
socket1.close()
SERVER:
import socketserver
class MiTcpHandler(socketserver.BaseRequestHandler):
def handle(self):
try:
self.cadena = self.request.recv(1024).decode('utf-8')
print("Cliente:", self.cadena)
self.CadenaSendServer = input("Sevidor: ")
self.request.send(self.CadenaSendServer.encode(
encoding='utf-8', errors='strict'))
except Exception as e:
print("error", e)
host = "localhost"
port = 9999
server1 = socketserver.TCPServer((host, port), MiTcpHandler)
print("Servidor Corriendo")
server1.serve_forever()
My problem is that when executing them, they connect without problems. First I send a message from client to server. Then I reply from the server to the client with another message. The problem is that when trying to send again a third message from client, the program (only client, server if it remains active) closes unexpectedly and shows the following message:
error [VinError 10053] A connection established by the software on your host computer has been canceled *
Someone please can help me with this error or have had experience in these cases. Or at least explain why it happens, if I can understand what happens then I solve it myself.
Thanks in advance, I will be here as long as necessary.