aboutsummaryrefslogtreecommitdiffstats
path: root/test/helper_tools/passive_close.py
blob: 6f97ea4fb9d322b436c84e3066d90b6c129d3f8f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import socketserver
from time import sleep


class service(socketserver.BaseRequestHandler):

    def handle(self):
        data = 'dummy'
        print("Client connected with ", self.client_address)
        while True:
            self.request.send(
                "HTTP/1.1 200 OK\r\nConnection: close\r\nContent-Length: 7\r\n\r\ncontent")
            data = self.request.recv(1024)
            if not len(data):
                print("Connection closed by remote: ", self.client_address)
                sleep(3600)


class ThreadedTCPServer(socketserver.ThreadingMixIn, socketserver.TCPServer):
    pass


server = ThreadedTCPServer(('', 1520), service)
server.serve_forever()