jhavl / swift

MIT License
92 stars 22 forks source link

"Could not connect to the Swift simulator" in Colab/Remote Notebook #45

Open YuhengZhi opened 1 year ago

YuhengZhi commented 1 year ago

Even though it looks like the implementation of SwiftRoute is attempting to support Colab, my recent tries to run the example code (the piece for running in jupyter notebook) in a Colab notebook has failed with the error message "Could not connect to the Swift simulator ". The same error is given when run in a remote non-colab notebook served on a personal server (but opened via the remote-ssh plugin of vs code).

The same code runs fine on a local jupyter notebook though. Both RTB and Swift are the latest versions via PIP.

I am sorry that web programming is not my most vital skill, so some initial digging & print statements on my side were not very fruitful. All I was able to identify was that this line timed out in the remote notebook, but returned "Connected" in a local notebook.

martinezpenya commented 8 months ago

I'm facing the same issue... I have a local notebook on docker container with python robotics, swift, etc... and I'm getting same error when trying to connect to Swift. Any update?

Davian1704 commented 3 months ago

I faced similar issues while trying to use the swift simulator on a jupyterhub running on a docker on the host machine. I've managed to fix it by changing the following:

In swift/SwiftRoute.py

I changed the websocket creation to be:

    start_server = websockets.serve(self.serve, "0.0.0.0", port)

I changed the url of the Swift Simulator to match the domain assigned to the server we are using, but if ran locally, localhost should be fine:

    url = f"http://domain:{server_port}/?{socket_port}"

Additionally, in the do_GET method I changed the address to match that of the url of the Swift Simulator:

    self.send_header(
        "Location",
        "http://domain:"
        + str(server_port)
        + "/?"
        + str(socket_port),
    )

In swift/out/_next/static/chunks/pages/index-0723cc3b940b78c7.js

The only change needed here was regarding to connecting to it through a domain, if not using a domain, localhost should work:

    var o="ws://domain:"+i+"/";

Additional Considerations

In the dockerfile, make sure that all the ports used by both the simulator and websocket are exposed and correctly mapped.

Here is the branched repository of swift-sim we use on our server: Repository