The correct way to get the port OctoPrint server is listening on?

In my plugin I'm using settings.getInt(["server", "port"]) to obtain the server port. However, I found out that when OctoPrint is launched with octoprint --port=5001, the value returned from settings.getInt(["server", "port"]) is still 5000.

What's the right way to get the port OctoPrint server is actually listening on inside a plugin?

I suppose @foosel would like to have your octoprint.log file.

I think I'd also wonder if you are trying to connect via IPv4 or IPv6. From my own naïve viewing of this code, it looks like it's hard-coded to 5000 but there's probably other stuff going on that's lost on me.

octoprint.log files doesn't show anything since nothing is being logged.

@foosel Hope you have a quick answer here?

She's in Germany, btw. If she does stop in, it will be hours from now.

Got it thx @OutsourcedGuru

Hi!
Keep in mind: Today is National Holiday.

I found the answer myself. It's actually documented here: http://docs.octoprint.org/en/master/plugins/mixins.html#octoprint.plugin.StartupPlugin.on_startup

But I wouldn't have found the document if I hadn't had traced the code all the way there. That's why software is so hard isn't it. :wink:

1 Like

Actually, I love open-source software. Many times people ask questions about OctoPrint or a plugin and I can just read through the code and sound authoritative, as if I actually knew what I were talking about. ha

Just back from vacation, but I see you already found your answer :slight_smile: :+1: