"Connection refused" when trying to connect to Reach through python s.socket(host,port) method


I am trying to connect to the Reach through python’s s.socket(host,port) method and I sometimes get the error: “Connection refused”. I am using the USB tcp connection feature that the Reach has, as explained here: https://docs.emlid.com/reach/software-development/#using-ethernet-over-usb.

This is sometimes fixed by rebooting the computer and reconnecting the GPS. Most of the code is shown below for convenience:


    s = socket.socket()         # Create a socket object
    host = rospy.get_param('~host', 'reach.local')
    port = rospy.get_param('~port', 12346)

    s.connect((host, port))

I read online that this issue could be related to the Reach being busy and not allowing tcp clients to connect. Please let me know if you know of any way I might be able to fix this issue.



Could you not just detect the connection failure and loop to try again?