diff --git a/ib_insync/client.py b/ib_insync/client.py
index <HASH>..<HASH> 100644
--- a/ib_insync/client.py
+++ b/ib_insync/client.py
@@ -205,8 +205,8 @@ class Client:
             self._logger.info(
                 f'Connecting to {host}:{port} with clientId {clientId}...')
             self.host = host
-            self.port = port
-            self.clientId = clientId
+            self.port = int(port)
+            self.clientId = int(clientId)
             self.connState = Client.CONNECTING
             timeout = timeout or None
             await asyncio.wait_for(self.conn.connectAsync(host, port), timeout)
diff --git a/ib_insync/ib.py b/ib_insync/ib.py
index <HASH>..<HASH> 100644
--- a/ib_insync/ib.py
+++ b/ib_insync/ib.py
@@ -1619,6 +1619,7 @@ class IB:
             self, host: str = '127.0.0.1', port: int = 7497,
             clientId: int = 1, timeout: Optional[float] = 4,
             readonly: bool = False, account: str = ''):
+        clientId = int(clientId)
         self.wrapper.clientId = clientId
         timeout = timeout or None
         try:
Explicit cast of port and clientId to integer