I am trying to use socketserver to create a simple server to send images to a client with TCP. First I send a catalogue to the client and then it responds with a request.
In the handle of my server, I have this loop :
class MainHandler(socketserver.BaseRequestHandler):
def handle(self):
while 1:
try:
# Sending the catalogue
# Using my methods to get my catalogue with a HTTP header
response = self.server.genHTTPRequest(self.server.init.catalogue)
self.request.sendall(response.encode())
# Response of the client
self.data = self.request.recv(1024).decode()
if self.data:
print("Data received : {}".format(self.data))
except:
print("transmission error")
break;
In the main I use this line to create my server (it's in an other file) :
mainServer = MainServer.MainServer((init.adresse, int(init.port)), MainServer.MainHandler)
When I launch this program, the client connect successfully and receive the catalogue but it sends back only some data and the program jump in the exception of the try/catch. Without the try/catch, I got this error :
self.data = self.request.recv(1024).decode()
ConnectionAbortedError: [WinError 10053] An established connection was aborted by the software in your host machine
I don't understand what is the problem, maybe a synchronization missing or may I need to use threads ?
Thank you for your help
(I am using python 3.3)