python-eel / Eel

A little Python library for making simple Electron-like HTML/JS GUI apps
MIT License
6.29k stars 582 forks source link

How to find the port number when ``port=0`` is used #672

Closed proneon267 closed 1 year ago

proneon267 commented 1 year ago

Describe the problem When port=0 is used, it chooses a random port number. So, how do I get the actual port number on which eel is listening?

johnegnatis commented 1 year ago

If anybody is still having this issue, the solution was very simple.

In your javascript: eel.set_host(window.location.origin);

proneon267 commented 1 year ago

I meant to get the port number in the python side. I ended up writing a custom function in python that returned an unused port and assigned eel to run on it.

johnegnatis commented 1 year ago

I meant to get the port number in the python side. I ended up writing a custom function that returned an unused port and assigned eel to run on it.

How did you get the port in Javascript if I may ask?

proneon267 commented 1 year ago

You can simply pass the generated port number from python side to the js side through eel object.