src/eric7/RemoteServer/EricServer.py

branch
eric7
changeset 11033
6b197c3389f7
parent 11030
46172eee98b6
child 11090
f5f5f5803935
--- a/src/eric7/RemoteServer/EricServer.py	Sat Nov 02 19:28:14 2024 +0100
+++ b/src/eric7/RemoteServer/EricServer.py	Sun Nov 03 12:34:02 2024 +0100
@@ -31,7 +31,7 @@
     Class implementing the eric remote server.
     """
 
-    def __init__(self, port=42024, useIPv6=False):
+    def __init__(self, port=42024, useIPv6=False, clientId=""):
         """
         Constructor
 
@@ -39,7 +39,14 @@
         @type int (optional)
         @param useIPv6 flag indicating to use IPv6 protocol (defaults to False)
         @type bool (optional)
+        @param clientId ID string used to check each received message for being
+            sent by a valid eric IDE (defaults to "")
+        @type str (optional)
         """
+        self.__clientId = clientId
+        self.__address = ("", port)
+        self.__useIPv6 = useIPv6
+
         self.__requestCategoryHandlerRegistry = {}
         # Dictionary containing the defined and registered request category
         # handlers. The key is the request category and the value is the respective
@@ -79,9 +86,6 @@
             self.__editorConfigRequestHandler.handleRequest,
         )
 
-        self.__address = ("", port)
-        self.__useIPv6 = useIPv6
-
     def getSelector(self):
         """
         Public method to get a reference to the selector object.
@@ -185,6 +189,16 @@
         if self.isSocketClosed(sock):
             return None
 
+        if self.__clientId and sock == self.__connection:
+            msgClientIdBytes = self.__receiveBytes(len(self.__clientId), sock)
+            try:
+                msgClientId = str(msgClientIdBytes, encoding="utf-8")
+            except UnicodeDecodeError:
+                msgClientId = str(bytes(msgClientIdBytes))
+            if msgClientId != self.__clientId:
+                print(f"Received illegal client ID '{msgClientId}'.")  # noqa: M801
+                return {}
+
         header = self.__receiveBytes(struct.calcsize(b"!II"), sock)
         if not header:
             return {}
@@ -326,7 +340,7 @@
         @param sock reference to the listening socket
         @type socket.socket
         """
-        connection, address = sock.accept()  # Should be ready to read
+        connection, address = sock.accept()  # Should be ready to read.
         if self.__connection is None:
             print(f"'eric-ide' connection from {address[0]}, port {address[1]}")
             # noqa: M801

eric ide

mercurial