1#!/usr/bin/env python3
2#
3# Copyright (C) 2022 Intel Corporation.
4#
5# SPDX-License-Identifier: BSD-3-Clause
6#
7import socket
8import sys
9
10if __name__ == "__main__":
11    HOST = '127.0.0.1'
12    PORT = 8193
13    SYS_REBOOT_REQ = 'req_sys_reboot'
14    MSG_LEN = 32
15
16    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
17    print(["Socket Created"])
18
19    try:
20        s.connect((HOST,PORT))
21        print("[Connection established]")
22    except Exception:
23        print('[Connection error:  ' + HOST + ":" + str(PORT)+']')
24        s.close()
25
26    try:
27        s.send(SYS_REBOOT_REQ.encode('utf-8'))
28    except Exception as _:
29        raise _
30    print(["System reboot request sent\n"])
31
32    try:
33        data_input = (s.recv(MSG_LEN).decode("UTF-8"))
34    except Exception:
35        pass
36    print("Waiting for ACK message...: ", data_input)
37    s.close()
38