#!/usr/bin/env python3 import sys #sys.path.append("..") #sys.path.append("../..") #sys.path.append("../../..") #from device_controller.concrete_component.device_simulator_common.server_udp_or_tcp import get_SocketServer_UDP_TCP #from device_simulator_common.server_udp_or_tcp import get_SocketServer_UDP_TCP from device_controller.concrete_component.device_simulator_common.server_udp_or_tcp import get_SocketServer_UDP_TCP #from server.server_udp_or_tcp import get_SocketServer_UDP_TCP HOST = "localhost" # Voir https://stackoverflow.com/questions/10085996/shutdown-socketserver-serve-forever-in-one-thread-python-application class DeviceSimulatorSBIG: #with socketserver_type((HOST, PORT), MyUDPorTCPHandler_classic) as myserver: myserver = None @classmethod def serve_forever(cls, PORT): #with get_SocketServer_UDP_TCP(HOST, PORT, "UDP") as myserver: myserver.serve_forever() cls.myserver = get_SocketServer_UDP_TCP(HOST, PORT, "UDP") print("******** myserver serve: *********", cls.myserver) try: cls.myserver.serve_forever() except KeyboardInterrupt: pass cls.myserver.server_close() cls.myserver.shutdown() @classmethod def stop(cls): print("******** myserver stop: *********", cls.myserver) cls.myserver.shutdown()