Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

View web server on other device broken #146

Open
MatthiasJ1 opened this issue Jan 31, 2025 · 7 comments
Open

View web server on other device broken #146

MatthiasJ1 opened this issue Jan 31, 2025 · 7 comments

Comments

@MatthiasJ1
Copy link

The web server works if running on the same machine. If run with --host 0.0.0.0, it can be accessed from another device. If I open <computer ip>:3939/viewer on my iPad, I will get the OCP viewer UI with the default OCP eye logo which I can view in 3D, but if I run show() on my computer, I get the following output on the OCP viewer server:

127.0.0.1 - - [31/Jan/2025 10:53:30] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [31/Jan/2025 10:53:30] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [31/Jan/2025 10:53:30] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [31/Jan/2025 10:53:30] "GET / HTTP/1.1" 200 -
[2025-01-31 10:53:30,928] ERROR in app: Exception on / [GET]
Traceback (most recent call last):
  File "/opt/homebrew/Caskroom/micromamba/envs/cad/lib/python3.13/site-packages/flask/app.py", line 1511, in wsgi_app
    response = self.full_dispatch_request()
  File "/opt/homebrew/Caskroom/micromamba/envs/cad/lib/python3.13/site-packages/flask/app.py", line 919, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/opt/homebrew/Caskroom/micromamba/envs/cad/lib/python3.13/site-packages/flask/app.py", line 917, in full_dispatch_request
    rv = self.dispatch_request()
  File "/opt/homebrew/Caskroom/micromamba/envs/cad/lib/python3.13/site-packages/flask/app.py", line 902, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)  # type: ignore[no-any-return]
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
  File "/opt/homebrew/Caskroom/micromamba/envs/cad/lib/python3.13/site-packages/flask_sock/__init__.py", line 62, in websocket_route
    f(ws, *args, **kwargs)
    ~^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Caskroom/micromamba/envs/cad/lib/python3.13/site-packages/ocp_vscode/standalone.py", line 220, in handle_message
    self.javascript_client.send(data)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'send'
@bernhard-42
Copy link
Owner

I just tried it on my machines:

Linux:

pip install ocp_vscode
cd build123d
pip install .  # to avoid the HashCode problem
python -m ocp-vscode --host="0.0.0.0"

Same machine

In [1]: from build123d import *
In [2]: from ocp_vscode import *
In [3]: b = Box(1,1,1)
In [4]: b = chamfer(b.edges(), 0.1)
In [5]: show(b)
UserWarning: The viewer doesn't seem to run
Port 3939 is open, using it
Jupyter console not installed
+

Other machine

In [1]: from build123d import *
In [2]: from ocp_vscode import *
In [3]: set_port(3939, host='192.168.178.41')
In [4]: b = Box(1,2,3)
In [5]: b = chamfer(b.edges(), 0.2)
In [6]: show(b)
+

In both cases the box will be shown in the viewer as expected

@bernhard-42
Copy link
Owner

And yes, the UserWarning: The viewer doesn't seem to run should not appear

@MatthiasJ1
Copy link
Author

I think your case might be slightly different. You need to open the viewer in the browser on Other machine while the server is running on Linux

@bernhard-42
Copy link
Owner

I did:

  • python -m ocp_vscode --host="0.0.0.0" on the remote Linux server (headless, no monitor)
  • On my Mac I run the browser and connect to the viewer on the Linux machine
  • Both from the Mac and the Linux server I can show objects.
  • I then opened the viewer from my iPad and again, when showing objects from both machines, they update the viewer on the iPad

Am I missing someting?

@bernhard-42
Copy link
Owner

The error that you see can only happen, if the viewer does not register back to the server.
Running python -m ocp_vscode --host="0.0.0.0" --debug you should see the line
Debug: Javascript listener registered {}
after your browser has connect to the viewer (i.e. flask)
Afterwards self.javascript_client will not be set to null again.

@bernhard-42
Copy link
Owner

Ha, I could (somehow) reproduce your error:
Assume your browser has connected to the viewer (flask server) and registered itself, see above.
When you now kill the python viewer on the server and start it gain, and immediately (!) want to show an object this error occurs. Reason: The websocket listener of the javascript browser (viewer) is not yet registered in the python server (flask).
Refresh your viewer browser page and you'll see Debug: Javascript listener registered {} again (in debug mode) and all works again.

Was this maybe your issue?

@bernhard-42
Copy link
Owner

@MatthiasJ1 I now show

No browser registered. Please open the viewer in a browser or refresh the viewer page

in the terminal of the viewer server when this error occurs.
Hope that helps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants