sbig_simulator.py
1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/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()