8 """ |
8 """ |
9 |
9 |
10 import json |
10 import json |
11 |
11 |
12 from PyQt6.QtCore import pyqtSignal, pyqtSlot |
12 from PyQt6.QtCore import pyqtSignal, pyqtSlot |
13 from PyQt6.QtNetwork import QTcpServer, QHostAddress |
13 from PyQt6.QtNetwork import QHostAddress, QTcpServer |
14 |
|
15 from eric7.EricWidgets import EricMessageBox |
|
16 |
14 |
17 from eric7 import Preferences, Utilities |
15 from eric7 import Preferences, Utilities |
|
16 from eric7.EricWidgets import EricMessageBox |
18 |
17 |
19 |
18 |
20 class EricJsonReader(QTcpServer): |
19 class EricJsonReader(QTcpServer): |
21 """ |
20 """ |
22 Class implementing a JSON based reader class. |
21 Class implementing a JSON based reader class. |
46 self.__connection = None |
45 self.__connection = None |
47 |
46 |
48 # setup the network interface |
47 # setup the network interface |
49 if ip is None: |
48 if ip is None: |
50 networkInterface = Preferences.getDebugger("NetworkInterface") |
49 networkInterface = Preferences.getDebugger("NetworkInterface") |
51 if networkInterface == "all" or "." in networkInterface: |
50 if networkInterface in ("allv4", "localv4") or "." in networkInterface: |
52 # IPv4 |
51 # IPv4 |
53 self.__hostAddress = "127.0.0.1" |
52 self.__hostAddress = "127.0.0.1" |
54 else: |
53 elif networkInterface in ("all", "allv6", "localv6"): |
55 # IPv6 |
54 # IPv6 |
56 self.__hostAddress = "::1" |
55 self.__hostAddress = "::1" |
|
56 else: |
|
57 self.__hostAddress = networkInterface |
57 else: |
58 else: |
58 self.__hostAddress = ip |
59 self.__hostAddress = ip |
59 self.listen(QHostAddress(self.__hostAddress)) |
60 self.listen(QHostAddress(self.__hostAddress)) |
60 |
61 |
61 self.newConnection.connect(self.handleNewConnection) |
62 self.newConnection.connect(self.handleNewConnection) |
62 |
63 |
63 ## Note: Need the port if writer is started external in debugger. |
64 ## Note: Need the address and port if client is started external in debugger. |
|
65 hostAddressStr = ( |
|
66 "[{0}]".format(self.__hostAddress) |
|
67 if ":" in self.__hostAddress |
|
68 else self.__hostAddress |
|
69 ) |
64 print( # __IGNORE_WARNING_M801__ |
70 print( # __IGNORE_WARNING_M801__ |
65 "JSON reader ({1}) listening on: {0:d}".format( |
71 "JSON server ({2}) listening on: {0}:{1:d}".format( |
66 self.serverPort(), self.__name |
72 hostAddressStr, self.serverPort(), self.__name |
67 ) |
73 ) |
68 ) |
74 ) |
69 |
75 |
70 def address(self): |
76 def address(self): |
71 """ |
77 """ |