import socket

class NetClient:
    TIMEOUT = 3
    def __init__(self, ip, port) -> None:
        self.ip = ip
        self.port = port

    def request(self, path, method='GET', body=''):
        sock = socket.socket()
        sock.settimeout(self.TIMEOUT)
        try:
            sock.connect((self.ip, self.port))
            req = '{} {} HTTP/1.1\r\nHost:\r\nContent-Length: {}\r\n\r\n{}'.format(method, path, len(body), body).encode()
            sock.sendall(req)
            data = sock.recv(1024)
            print(data)
            sock.close()
            print(req)
        except Exception as e:
            print(e)


def main():
    client = NetClient('localhost', 9000)
    # client.request('/index.html', 'GET', '')
    client.request('/fw.bin', 'GET', '')

if __name__ == '__main__':
    main()