26 @signal dataReceived(object) emitted after a data object was received |
26 @signal dataReceived(object) emitted after a data object was received |
27 """ |
27 """ |
28 |
28 |
29 dataReceived = pyqtSignal(object) |
29 dataReceived = pyqtSignal(object) |
30 |
30 |
31 def __init__(self, name="", interface="127.0.0.1", parent=None): |
31 def __init__(self, name="", interface="127.0.0.1", parent=None, releaseMode=False): |
32 """ |
32 """ |
33 Constructor |
33 Constructor |
34 |
34 |
35 @param name name of the server (used for output only) (defaults to "") |
35 @param name name of the server (used for output only) (defaults to "") |
36 @type str (optional) |
36 @type str (optional) |
37 @param interface network interface to be used (IP address or one of "all", |
37 @param interface network interface to be used (IP address or one of "all", |
38 "allv4", "allv6", "localv4" or "localv6") (defaults to "127.0.0.1") |
38 "allv4", "allv6", "localv4" or "localv6") (defaults to "127.0.0.1") |
39 @type str (optional) |
39 @type str (optional) |
40 @param parent reference to the parent object (defaults to None) |
40 @param parent reference to the parent object (defaults to None) |
41 @type QObject (optional) |
41 @type QObject (optional) |
|
42 @param releaseMode flag indicating the mode of operations (defaults to False) |
|
43 @type bool (optional) |
42 """ |
44 """ |
43 super().__init__(parent) |
45 super().__init__(parent) |
44 |
46 |
45 self.__name = name |
47 self.__name = name |
46 self.__connection = None |
48 self.__connection = None |
56 self.__hostAddress = interface |
58 self.__hostAddress = interface |
57 self.listen(QHostAddress(self.__hostAddress)) |
59 self.listen(QHostAddress(self.__hostAddress)) |
58 |
60 |
59 self.newConnection.connect(self.handleNewConnection) |
61 self.newConnection.connect(self.handleNewConnection) |
60 |
62 |
61 ## Note: Need the address and port if client is started external in debugger. |
63 if not releaseMode: |
62 hostAddressStr = ( |
64 ## Note: Need the address and port if client is started external in |
63 "[{0}]".format(self.__hostAddress) |
65 ## debugger. |
64 if ":" in self.__hostAddress |
66 hostAddressStr = ( |
65 else self.__hostAddress |
67 "[{0}]".format(self.__hostAddress) |
66 ) |
68 if ":" in self.__hostAddress |
67 print( # __IGNORE_WARNING_M-801__ |
69 else self.__hostAddress |
68 "JSON server ({2}) listening on: {0}:{1:d}".format( |
|
69 hostAddressStr, self.serverPort(), self.__name |
|
70 ) |
70 ) |
71 ) |
71 print( # __IGNORE_WARNING_M-801__ |
|
72 f"JSON server ({self.__name}) listening on:" |
|
73 f" {hostAddressStr}:{self.serverPort():d}" |
|
74 ) |
72 |
75 |
73 def address(self): |
76 def address(self): |
74 """ |
77 """ |
75 Public method to get the host address. |
78 Public method to get the host address. |
76 |
79 |