OpenRemote Controller Auto-Discovery
Overview
OpenRemote controllers support auto-discovery by listening for discovery requests on a multicast group and responding to them via TCP. Clients making controller auto-discovery requests are expected to start a TCP server on port 2346 before sending auto-discovery requests to the multicast group.
Controller-Side Implementation and Configuration
Initialization
A servlet context listener class, org.openremote.controller.bootstrap.servlet.ServletStartup is responsible for starting the server on the controller which responds to controller auto-discovery requests, which is implemented in the IPAutoDiscoveryServer class.
IPAutoDiscoveryServer
The server that listens on the multicast group for auto-discovery requests is implemented in the IPAutoDiscoveryServer class (in the org.openremote.controller.net package). It uses the org.openremote.controller.ControllerConfiguration class to determine the multicast group (IP address) and port on which to listen, which in turn uses the multicast.address and multicast.port properties from the config.properties file located in the WEB-INF/classes directory in the webapp deployment.
The IPAutoDiscoveryServer joins the configured multicast group on the configured port and listens for UDP packets. Once any UDP packet is received, regardless of its contents, a new thread is created from the org.openremote.controller.net.IPResponseTCPClient class, initialized with the source IP address from the received UDP packet.
IPResponseTCPClient
The IPResponseTcpClient class is responsible for sending the URL for the controller to a device which requested it via a UDP packet sent to the appropriate multicast group and port. This class is typically instantiated and run in a new thread by an instance of the IPAutoDiscoveryServer class. Its constructor takes an InetAddress representing the IP address of the device which made the auto-discovery request as a parameter, and its run method opens a TCP socket to the server running on port 2346 on that IP address. It writes a URL to that socket and then closes it. The URL is constructed in the following statement:
String data = "http: + NetworkUtil.getLocalhostIP() + ":" + configuration.getWebappPort() + "/"
+ configuration.getWebappName();