|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objecttuwien.auto.calimero.knxnetip.Discoverer
public class Discoverer
Does KNXnet/IP discovery and retrieval of self description from other devices.
Discovery searches and description requests can be run in blocking mode or asynchronous
in the background.
Supports networks with routers doing network address translation.
Requests for self description are sent using the UDP transport protocol.
Due to protocol limitations, only IPv4 addresses are supported when network address
translation is not used. With NAT enabled, IPv6 addresses can be used as well.
A note on (not) using network address translation (NAT):
If discovery or description attempts fail indicating a timeout limit, it might be
possible that NAT is used on routers while traversing the network, so the solution
would be to enable the use of NAT.
On the other hand, if NAT is used but not supported by the answering device, no
response is received and a timeout will occur nevertheless. That's life.
Field Summary | |
---|---|
static java.lang.String |
LOG_SERVICE
Name of the log service used by a discoverer. |
static java.lang.String |
SEARCH_MULTICAST
Multicast IP address used for discovery, multicast group is "224.0.23.12". |
static int |
SEARCH_PORT
Port number used for discovery, port is 3671. |
Constructor Summary | |
---|---|
Discoverer(java.net.InetAddress localHost,
int localPort,
boolean useNAT)
Creates a new Discoverer and allows to specify a local host. |
|
Discoverer(int localPort,
boolean useNAT)
Creates a new Discoverer. |
Method Summary | |
---|---|
void |
clearSearchResponses()
Removes all search responses collected so far. |
DescriptionResponse |
getDescription(java.net.InetSocketAddress server,
int timeout)
Sends a description request to server and waits at most
timeout seconds for the answer message to arrive. |
SearchResponse[] |
getSearchResponses()
Returns all collected search responses received by searches so far. |
boolean |
isSearching()
Returns true if a search is currently running. |
void |
startSearch(int timeout,
boolean wait)
Starts a new discovery from all found network interfaces. |
void |
startSearch(int localPort,
java.net.NetworkInterface ni,
int timeout,
boolean wait)
Starts a new discovery, the localPort and network interface can be
specified. |
void |
stopSearch()
Stops every search currently running within this Discoverer. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String LOG_SERVICE
public static final java.lang.String SEARCH_MULTICAST
public static final int SEARCH_PORT
Constructor Detail |
---|
public Discoverer(java.net.InetAddress localHost, int localPort, boolean useNAT) throws KNXException
See Discoverer(int, boolean)
for additional description.
The localHost
is used to specify a particular local host address,
used as response destination address when doing discovery / description. By
default, the local host is used as obtained by InetAddress.getLocalHost()
.
The returned address is quite system dependent and might not always be useful in
some situations. So it can be overruled specifying a local host address using this
constructor.
localHost
- local host address used for discovery / description responseslocalPort
- the port number used to bind a socket, a valid port is in the
range of 1 to 65535, or use 0 to pick an arbitrary unused (ephemeral) port.
Note that a specified valid port does not ensure a successful bind in
subsequent discoverer operations due to operating system dependencies.useNAT
- true
to use a NAT (network address translation) aware
discovery/description mechanism, false
to use the default way
KNXException
- if local host can't be usedpublic Discoverer(int localPort, boolean useNAT) throws KNXException
Network address translation:
If subsequent discovery or description attempts fail indicating a timeout limit, it
might be possible that network address translation (NAT) is used on routers while
traversing the network (besides the other reason that timeouts are too short). This
would effectively stop any communication done in the standard way, due to the way
the HPAI structure is used by default.
Setting the parameter for indicating use of NAT to true
takes
account of such routers, leading to the desired behavior.
localPort
- the port number used to bind a socket, a valid port is in the
range of 1 to 65535, or use 0 to pick an arbitrary unused (ephemeral) port.
Note that a specified valid port does not ensure a successful bind in
subsequent discoverer operations due to operating system dependencies.useNAT
- true
to use a NAT (network address translation) aware
discovery/description mechanism, false
to use the default way
KNXException
- on error getting usable local hostMethod Detail |
---|
public final void clearSearchResponses()
public DescriptionResponse getDescription(java.net.InetSocketAddress server, int timeout) throws KNXException
server
and waits at most
timeout
seconds for the answer message to arrive.
server
- the InetSocketAddress of the server the description is requested fromtimeout
- time window in seconds to wait for answer message, 0 < timeout
< (Integer.MAX_VALUE
/ 1000)
KNXException
- on network I/O error
KNXTimeoutException
- if the timeout was reached before the description
response arrived
KNXInvalidResponseException
- if a received message from server
does not match the expected responsepublic final SearchResponse[] getSearchResponses()
As long as searches are running, new responses might be added to the list of responses.
SearchResponse
sstopSearch()
public final boolean isSearching()
true
if a search is currently running.
boolean
showing the search statepublic void startSearch(int timeout, boolean wait) throws KNXException
The search will continue for timeout
seconds, or infinite if timeout
value is zero. During this time, search responses will get collected asynchronous
in the background by this Discoverer.
With wait
you can force this method into blocking mode to wait until
the search finished, otherwise the method returns with the search running in the
background.
A search has finished if either the timeout
was reached, all
background receiver stopped (all responses received) or stopSearch()
was
invoked.
timeout
- time window in seconds during which search response messages will
get collected, timeout >= 0. If timeout is 0, no timeout is set, the search
has to be stopped with stopSearch
.wait
- true
to block until end of search before return
KNXException
- on network I/O errorpublic void startSearch(int localPort, java.net.NetworkInterface ni, int timeout, boolean wait) throws KNXException
localPort
and network interface can be
specified.
The search will continue for timeout
seconds, or infinite if timeout
value is zero. During this time, search responses will get collected asynchronous
in the background by this Discoverer
.
With wait
you can force this method into blocking mode to wait until
the search finished, otherwise the method returns with the search running in the
background.
A search is finished if either the timeout
was reached or the
background receiver stopped.
The reason the localPort
parameter is specified here, in addition to
the port queried at Discoverer(int, boolean)
, is to distinguish between
search responses if more searches are running concurrently.
localPort
- the port used to bind the socket, a valid port is 0 to 65535, if
localPort is zero an arbitrary unused (ephemeral) port is pickedni
- the NetworkInterface
used for sending outgoing multicast
messages, or null
to use the default multicast interfacetimeout
- time window in seconds during which search response messages will
get collected, timeout >= 0. If timeout is zero, no timeout is set, the
search has to be stopped with stopSearch()
.wait
- true
to block until end of search before return
KNXException
- on network I/O errorMulticastSocket
,
NetworkInterface
public final void stopSearch()
Already gathered search responses from a search will not be removed.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |