1

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)

Loric
  • 1,678
  • 8
  • 28
  • 48
  • I think the connection is being reset. Try wiresharking the line (loopback). You can also try disabling your firewall or anti-viruses. – jary Jan 07 '13 at 19:26
  • Thank you for your response, I have fixed the problem. It was because the client sent wrong information and there was a problem with the recv and the client cut the connection. By the way, I decided to use SocketServer for this project. – Loric Jan 09 '13 at 00:06

1 Answers1

0

The problem would be because of sendall(response.encode()) and this self.request.recv(1024).decode() has been done in the same socket and it could lead to ConnectionAbortedError.

You need to read all the data from the socket before putting other data into the socket. Like flushing of data.