Porgramatically finding Jettys WebServer port

Hi all,

Apologies if I have missed the post. I have a servlet, I have written for a new binding. I can find the local IP address used to connect to a remote device by connecting via a socket, and getting the local address. So that solves the local IP address used to route to a given IP. However, I am missing something simple I’m sure, but how can I find in Java the port that the WebServer is listening on, which the servlet attaches to? Basically I need to send to the remote device, the setting of where it can target its data pushes to for part of its protocol.(IP sorted it’s just the port that I cant quite figure out).
Any answers, or directions much appreciated.

Thanks in advance

Look at mdns broadcaster which sends information about OH installation.
Can’t point you exactly, but there are two places which know 1) OH address - it is NetworkUtils which allow you to obtain configured primary address 2) org.osgi.service.http.port / org.osgi.service.http.port.secure - these are system properties and configuration properties used by default to define HTTP/HTTPS port used by embedded jetty.

1 Like

Perfect thank you @splatch will have a look through those two area’s, pointers is precisely what I needed thanks. Point 2) sounds precisely like what I couldn’t locate info on, point1) will also be useful to double check the detected data.
Thanks again!

Thank you! I just tried with a quick debug - it correct gave the http port the server is listening on with:

logger.warn("Servlet HTTP port : {}", System.getProperty("org.osgi.service.http.port"));
logger.warn("Servlet HTTPS port : {}", System.getProperty("org.osgi.service.https.port"));

Which was precisely what I couldn’t find before.

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.