0

I have a weight indicator and I am communicating with that indicator through a tcp/ip protocol.And it's working fine.But when indicator is off and I try to connect with the indicator it takes too long time to return TimeoutError response.So I want to reduce the time I mean if indicator is off then I want the timeoutError fast.Here is my tcp client code

class TcpClient:
   def __init__(self):
       self.ip_address = ip_address
       self.port = port
       # Check if socket is connect or not.If socket is connected then it will return 0 otherwise it will return -1.
       # Also creates a new socket object using the socket library in Python
       self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
       self.is_connected = False

   def connect(self):
       try:
           self.socket.connect((self.ip_address, self.port))
           self.is_connected = True
           return("tcp is connected")
       except ConnectionRefusedError as e:
           self.is_connected = False
           return (f"Connection refused: A connection attempt failed because the indicator did not properly respond after a period of time")
       except TimeoutError as e:
           self.is_connected = False
           return (f"Connection refused: A connection attempt failed because the indicator did not properly respond after a period of time")
Manvi
  • 171
  • 11

0 Answers0