public abstract class JmDNS
extends java.lang.Object
implements java.io.Closeable
Modifier and Type | Class and Description |
---|---|
static interface |
JmDNS.Delegate |
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
VERSION
The version of JmDNS.
|
Constructor and Description |
---|
JmDNS() |
Modifier and Type | Method and Description |
---|---|
abstract void |
addServiceListener(java.lang.String type,
ServiceListener listener)
Listen for services of a given type.
|
abstract void |
addServiceTypeListener(ServiceTypeListener listener)
Listen for service types.
|
static JmDNS |
create()
Create an instance of JmDNS.
|
static JmDNS |
create(java.net.InetAddress addr)
Create an instance of JmDNS and bind it to a specific network interface given its IP-address.
|
static JmDNS |
create(java.net.InetAddress addr,
java.lang.String name)
Create an instance of JmDNS and bind it to a specific network interface given its IP-address.
|
static JmDNS |
create(java.lang.String name)
Create an instance of JmDNS.
|
abstract JmDNS.Delegate |
getDelegate()
Returns the instance delegate
|
abstract java.lang.String |
getHostName()
Return the HostName associated with this JmDNS instance.
|
abstract java.net.InetAddress |
getInetAddress()
Return the address of the interface to which this instance of JmDNS is bound.
|
abstract java.net.InetAddress |
getInterface()
Deprecated.
do not use this implementation yields unpredictable results use
getInetAddress() |
abstract java.lang.String |
getName()
Return the name of the JmDNS instance.
|
abstract ServiceInfo |
getServiceInfo(java.lang.String type,
java.lang.String name)
Get service information.
|
abstract ServiceInfo |
getServiceInfo(java.lang.String type,
java.lang.String name,
boolean persistent)
Get service information.
|
abstract ServiceInfo |
getServiceInfo(java.lang.String type,
java.lang.String name,
boolean persistent,
long timeout)
Get service information.
|
abstract ServiceInfo |
getServiceInfo(java.lang.String type,
java.lang.String name,
long timeout)
Get service information.
|
abstract ServiceInfo[] |
list(java.lang.String type)
Returns a list of service infos of the specified type.
|
abstract ServiceInfo[] |
list(java.lang.String type,
long timeout)
Returns a list of service infos of the specified type.
|
abstract java.util.Map<java.lang.String,ServiceInfo[]> |
listBySubtype(java.lang.String type)
Returns a list of service infos of the specified type sorted by subtype.
|
abstract java.util.Map<java.lang.String,ServiceInfo[]> |
listBySubtype(java.lang.String type,
long timeout)
Returns a list of service infos of the specified type sorted by subtype.
|
abstract void |
printServices()
Deprecated.
since 3.2.2
|
abstract void |
registerService(ServiceInfo info)
Register a service.
|
abstract boolean |
registerServiceType(java.lang.String type)
Register a service type.
|
abstract void |
removeServiceListener(java.lang.String type,
ServiceListener listener)
Remove listener for services of a given type.
|
abstract void |
removeServiceTypeListener(ServiceTypeListener listener)
Remove listener for service types.
|
abstract void |
requestServiceInfo(java.lang.String type,
java.lang.String name)
Request service information.
|
abstract void |
requestServiceInfo(java.lang.String type,
java.lang.String name,
boolean persistent)
Request service information.
|
abstract void |
requestServiceInfo(java.lang.String type,
java.lang.String name,
boolean persistent,
long timeout)
Request service information.
|
abstract void |
requestServiceInfo(java.lang.String type,
java.lang.String name,
long timeout)
Request service information.
|
abstract JmDNS.Delegate |
setDelegate(JmDNS.Delegate value)
Sets the instance delegate
|
abstract void |
unregisterAllServices()
Unregister all services.
|
abstract void |
unregisterService(ServiceInfo info)
Unregister a service.
|
public static final java.lang.String VERSION
public static JmDNS create() throws java.io.IOException
Create an instance of JmDNS.
Note: This is a convenience method. The preferred constructor is create(InetAddress, String)
.
Check that your platform correctly handle the default localhost IP address and the local hostname. In doubt use the explicit constructor.
This call is equivalent to create(null, null)
.
java.io.IOException
- if an exception occurs during the socket creationcreate(InetAddress, String)
public static JmDNS create(java.net.InetAddress addr) throws java.io.IOException
Create an instance of JmDNS and bind it to a specific network interface given its IP-address.
Note: This is a convenience method. The preferred constructor is create(InetAddress, String)
.
Check that your platform correctly handle the default localhost IP address and the local hostname. In doubt use the explicit constructor.
This call is equivalent to create(addr, null)
.
addr
- IP address to bind to.java.io.IOException
- if an exception occurs during the socket creationcreate(InetAddress, String)
public static JmDNS create(java.lang.String name) throws java.io.IOException
Create an instance of JmDNS.
Note: This is a convenience method. The preferred constructor is create(InetAddress, String)
.
Check that your platform correctly handle the default localhost IP address and the local hostname. In doubt use the explicit constructor.
This call is equivalent to create(null, name)
.
name
- name of the newly created JmDNSjava.io.IOException
- if an exception occurs during the socket creationcreate(InetAddress, String)
public static JmDNS create(java.net.InetAddress addr, java.lang.String name) throws java.io.IOException
Create an instance of JmDNS and bind it to a specific network interface given its IP-address.
Ifaddr
parameter is null this method will try to resolve to a local IP address of the machine using a network discovery:
net.mdns.interface
NetworkTopologyDiscovery
to find a valid network interface and IP.name
parameter is null will use the hostname. The hostname is determined by the following algorithm:
JmDNS name
or computer
if null.'.'
replace them by '-'
.local.
at the end of the name.
Note: If you need to use a custom NetworkTopologyDiscovery
it must be setup before any call to this method. This is done by setting up a NetworkTopologyDiscovery.Factory.ClassDelegate
and installing it using
NetworkTopologyDiscovery.Factory.setClassDelegate(NetworkTopologyDiscovery.Factory.ClassDelegate)
. This must be done before creating a JmDNS
or JmmDNS
instance.
addr
- IP address to bind to.name
- name of the newly created JmDNSjava.io.IOException
- if an exception occurs during the socket creationpublic abstract java.lang.String getName()
public abstract java.lang.String getHostName()
public abstract java.net.InetAddress getInetAddress() throws java.io.IOException
java.io.IOException
- if there is an error in the underlying protocol, such as a TCP error.@Deprecated public abstract java.net.InetAddress getInterface() throws java.io.IOException
getInetAddress()
java.io.IOException
- if there is an error in the underlying protocol, such as a TCP error.public abstract ServiceInfo getServiceInfo(java.lang.String type, java.lang.String name)
type
- fully qualified service type, such as _http._tcp.local.
.name
- unqualified service name, such as foobar
.public abstract ServiceInfo getServiceInfo(java.lang.String type, java.lang.String name, long timeout)
type
- full qualified service type, such as _http._tcp.local.
.name
- unqualified service name, such as foobar
.timeout
- timeout in milliseconds. Typical timeout should be 5s.public abstract ServiceInfo getServiceInfo(java.lang.String type, java.lang.String name, boolean persistent)
type
- fully qualified service type, such as _http._tcp.local.
.name
- unqualified service name, such as foobar
.persistent
- if true
ServiceListener.resolveService will be called whenever new new information is received.public abstract ServiceInfo getServiceInfo(java.lang.String type, java.lang.String name, boolean persistent, long timeout)
type
- full qualified service type, such as _http._tcp.local.
.name
- unqualified service name, such as foobar
.timeout
- timeout in milliseconds. Typical timeout should be 5s.persistent
- if true
ServiceListener.resolveService will be called whenever new new information is received.public abstract void requestServiceInfo(java.lang.String type, java.lang.String name)
type
- full qualified service type, such as _http._tcp.local.
.name
- unqualified service name, such as foobar
.public abstract void requestServiceInfo(java.lang.String type, java.lang.String name, boolean persistent)
type
- full qualified service type, such as _http._tcp.local.
.name
- unqualified service name, such as foobar
.persistent
- if true
ServiceListener.resolveService will be called whenever new new information is received.public abstract void requestServiceInfo(java.lang.String type, java.lang.String name, long timeout)
type
- full qualified service type, such as _http._tcp.local.
.name
- unqualified service name, such as foobar
.timeout
- timeout in millisecondspublic abstract void requestServiceInfo(java.lang.String type, java.lang.String name, boolean persistent, long timeout)
type
- full qualified service type, such as _http._tcp.local.
.name
- unqualified service name, such as foobar
.persistent
- if true
ServiceListener.resolveService will be called whenever new new information is received.timeout
- timeout in millisecondspublic abstract void addServiceTypeListener(ServiceTypeListener listener) throws java.io.IOException
listener
- listener for service typesjava.io.IOException
- if there is an error in the underlying protocol, such as a TCP error.public abstract void removeServiceTypeListener(ServiceTypeListener listener)
listener
- listener for service typespublic abstract void addServiceListener(java.lang.String type, ServiceListener listener)
_http._tcp.local.
.type
- full qualified service type, such as _http._tcp.local.
.listener
- listener for service updatespublic abstract void removeServiceListener(java.lang.String type, ServiceListener listener)
type
- full qualified service type, such as _http._tcp.local.
.listener
- listener for service updatespublic abstract void registerService(ServiceInfo info) throws java.io.IOException
ServiceInfo
is bound to this JmDNS
instance, and should not be reused for any other registerService(ServiceInfo).info
- service info to registerjava.io.IOException
- if there is an error in the underlying protocol, such as a TCP error.public abstract void unregisterService(ServiceInfo info)
Note: Unregistered services will not disappear form the list of services immediately. According to the specification, when unregistering services we send goodbye packets and then wait 1s before purging the cache.
This is support for shared records that can be rescued by some other cooperation DNS.
Clients receiving a Multicast DNS Response with a TTL of zero SHOULD NOT immediately delete the record from the cache, but instead record a TTL of 1 and then delete the record one second later.
info
- service info to removepublic abstract void unregisterAllServices()
public abstract boolean registerServiceType(java.lang.String type)
Service types are automatically registered as they are discovered.
type
- full qualified service type, such as _http._tcp.local.
.true
if the type or subtype was added, false
if the type was already registered.@Deprecated public abstract void printServices()
public abstract ServiceInfo[] list(java.lang.String type)
type
- Service type name, such as _http._tcp.local.
.public abstract ServiceInfo[] list(java.lang.String type, long timeout)
type
- Service type name, such as _http._tcp.local.
.timeout
- timeout in milliseconds. Typical timeout should be 6s.public abstract java.util.Map<java.lang.String,ServiceInfo[]> listBySubtype(java.lang.String type)
type
- Service type name, such as _http._tcp.local.
.public abstract java.util.Map<java.lang.String,ServiceInfo[]> listBySubtype(java.lang.String type, long timeout)
type
- Service type name, such as _http._tcp.local.
.timeout
- timeout in milliseconds. Typical timeout should be 6s.public abstract JmDNS.Delegate getDelegate()
public abstract JmDNS.Delegate setDelegate(JmDNS.Delegate value)
value
- new instance delegate