Exemplo n.º 1
0
def check_server(address, date):
    # create client side socket
    checker = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

    # create the proper request string with a helper function
    request = Analysis.date_to_request(date)

    # inside a try in case the connection fails the exception can be handled differently to prevent data loss
    # its not necessary currently but could be if things are added to it
    try:
        # connect to server and send request
        checker.connect(address)
        checker.send(request.encode(encoding='utf-8'))

        json_data = checker.recv(10000).decode(encoding='utf-8')  # get response from server and decode

        return pandas.read_json(json_data)  # return
    finally:
        checker.close()  # close connection no matter what