1

TCP で画像をクライアントに送信する単純なサーバーを作成するために socketserver を使用しようとしています。最初にクライアントにカタログを送信すると、クライアントからリクエストが返されます。

サーバーのハンドルには、次のループがあります。

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;

主に、この行を使用してサーバーを作成します(別のファイルにあります):

mainServer = MainServer.MainServer((init.adresse, int(init.port)), MainServer.MainHandler)

このプログラムを起動すると、クライアントは正常に接続してカタログを受信しますが、一部のデータのみを返し、プログラムは try/catch を除いてジャンプします。try/catch がないと、次のエラーが発生しました。

self.data = self.request.recv(1024).decode()
ConnectionAbortedError: [WinError 10053] An established connection was aborted by the software in your host machine

何が問題なのかわかりません。おそらく同期が失われているのでしょうか、それともスレッドを使用する必要があるのでしょうか?

ご協力ありがとうございました

(私はpython 3.3を使用しています)

4

1 に答える 1