Skip to content
mec_simulator.py 1.4 KiB
Newer Older
Yann Garcia's avatar
Yann Garcia committed
# Very basic MEC PLAT simulator

import http.server
import socketserver
import mec_http_server
import threading
import sys, os, time
import msvcrt

# MEC simulator IPv4 address
#ADDRESS_BINDING = '172.28.4.87'
#ADDRESS_BINDING = '192.168.1.21'
ADDRESS_BINDING = '192.168.0.5'
#ADDRESS_BINDING = '127.0.0.1'
# MEC simulator IPv4 listening port
PORT_NUMBER = 8081

# TODO Add Linux support for detecting keyboard input from the terminal?
def getch():
    """ Capture keybord entry. """
    return msvcrt.getch()
# End of function getch

if __name__ == '__main__':
    exit = False
    try:
        # Create a web server and define the handler to manage the incoming request
        server = socketserver.TCPServer((ADDRESS_BINDING, PORT_NUMBER), mec_http_server.myHandler)
        print ('Started httpserver on port ' , PORT_NUMBER)
        # Wait forever for incoming http requests in background
        #server.serve_forever()
        threading.Thread(target=server.serve_forever).start()
        # Use keybord entries to trigger notifications
        while exit == False:
            ch = getch()
            if ch == b'\x03':
                exit = True
            else:
                print(">>> ch= ", ch)
        server.shutdown()
        server.socket.close()
    except KeyboardInterrupt:
        print ('^C received, shutting down the web server')
        server.shutdown()
        server.socket.close()
# End of __main__