I know how to check if the connection is up or not when I previusly got a connection from my client…
But at startup I’m planning to use RTDE on the robot controller and use the local host, crontab will then execute my client.
To be able to know when the server is up and running I have to test the connection, before I try to connect with the server. When I get an answer from the host/port, the RTDE-server isn’t really up and running, so I got to add a 20 second delay before I connect or I get errors.
I don’t like to use delays. Is there another way to know if the RTDE server is ready to be connected to?
# Code that I use import socket import time def WaitForPoly(host , port): sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.settimeout(2) result = sock.connect_ex(host,port) if result == 0: print 'Port open' return True else: print 'Port closed, message returned: '+str(result) return False while not WaitForPoly('localhost' , 30004): time.sleep(1) # THIS IS BAD CODE time.sleep(20)