public class NetworkCardDiscoverer
extends Object
package test.zebra.sdk.discovery.examples;
import java.util.*;
import com.zebra.sdk.common.card.printer.discovery.NetworkCardDiscoverer;
import com.zebra.sdk.printer.discovery.*;
public class NetworkCardDiscovererExample {
public static void main(String[] args) {
DiscoveryHandler discoveryHandler = new DiscoveryHandler() {
List<DiscoveredPrinter> printers = new ArrayList<DiscoveredPrinter>();
public void foundPrinter(DiscoveredPrinter printer) {
printers.add(printer);
}
public void discoveryFinished() {
for (DiscoveredPrinter printer : printers) {
System.out.println(printer);
}
System.out.println("Discovered " + printers.size() + " printers.");
}
public void discoveryError(String message) {
System.out.println("An error occurred during discovery : " + message);
}
};
try {
System.out.println("Starting printer discovery.");
NetworkCardDiscoverer.findPrinters(discoveryHandler);
} catch (DiscoveryException e) {
e.printStackTrace();
}
}
}
Modifier and Type | Method and Description |
---|---|
static void |
directedBroadcast(DiscoveryHandler discoveryHandler,
String ipAddress)
Sends a directed broadcast discovery packet to the subnet specified by
ipAddress . |
static void |
findPrinters(DiscoveryHandler discoveryHandler)
This method will search the network using a combination of discovery methods to find printers on the network.
|
static void |
findPrinters(DiscoveryHandler discoveryHandler,
java.util.List<String> printersToFind)
Sends a discovery request to the list of printer DNS names or IPs in
printersToFind . |
static void |
localBroadcast(DiscoveryHandler discoveryHandler)
Sends a local broadcast packet.
|
static void |
setDiscoveryConfiguration(DiscoveryConfiguration discoveryConfiguration)
Sets the network discovery configuration parameters.
|
static void |
subnetSearch(DiscoveryHandler discoveryHandler,
String subnetRange)
Sends a discovery packet to the IPs specified in the
subnetRange . |
public static void setDiscoveryConfiguration(DiscoveryConfiguration discoveryConfiguration)
discoveryConfiguration
- the network discovery configuration.public static void subnetSearch(DiscoveryHandler discoveryHandler, String subnetRange) throws DiscoveryException
subnetRange
. Subnet searches are defined by the first three subnet octets, followed by a
range, such as 192.168.2. This method accepts IP addresses of the form, assuming a subnet of 192.168.2:
DiscoveryHandler.foundPrinter(DiscoveredPrinter)
method for each printer that is found during discovery.
DiscoveryHandler.discoveryFinished()
will be invoked when the discovery is finished and DiscoveryHandler.discoveryError(String)
will be
invoked when any errors are encountered during discovery. When DiscoveryHandler.discoveryError(String)
is invoked, the discovery will be canceled and
DiscoveryHandler.discoveryFinished()
will not be invoked. DiscoveryHandler.foundPrinter(DiscoveredPrinter)
method will only be invoked on the
first occurrence.discoveryHandler
- a DiscoveryHandler
instance that is used to handle discovery events (e.g. found a printer, errors, discovery finished).subnetRange
- the subnet search range.DiscoveryException
- if an error occurs while starting the discovery (errors during discovery will be sent via
DiscoveryHandler.discoveryError(String)
).public static void directedBroadcast(DiscoveryHandler discoveryHandler, String ipAddress) throws DiscoveryException
ipAddress
. Directed broadcasts are defined by the first three subnet
octets, followed by 255, such as 192.168.2.255. This method accepts IP addresses of the form, assuming a subnet of 192.168.2:
DiscoveryHandler.foundPrinter(DiscoveredPrinter)
method for each printer that is found during discovery.
DiscoveryHandler.discoveryFinished()
will be invoked when the discovery is finished and DiscoveryHandler.discoveryError(String)
will be
invoked when any errors are encountered during discovery. When DiscoveryHandler.discoveryError(String)
is invoked, the discovery will be canceled and
DiscoveryHandler.discoveryFinished()
will not be invoked.DiscoveryHandler.foundPrinter(DiscoveredPrinter)
method will only be invoked on the
first occurrence.discoveryHandler
- a DiscoveryHandler
instance that is used to handle discovery events (e.g. found a printer, errors, discovery finished).ipAddress
- the IP address of the subnet.DiscoveryException
- if an error occurs while starting the discovery (errors during discovery will be sent via
DiscoveryHandler.discoveryError(String)
).public static void localBroadcast(DiscoveryHandler discoveryHandler) throws DiscoveryException
DiscoveryHandler.foundPrinter(DiscoveredPrinter)
method for each printer that is found
during discovery. DiscoveryHandler.discoveryFinished()
will be invoked when the discovery is finished and
DiscoveryHandler.discoveryError(String)
will be invoked when any errors are encountered during discovery. When
DiscoveryHandler.discoveryError(String)
is invoked, the discovery will be canceled and DiscoveryHandler.discoveryFinished()
will not be
invoked.DiscoveryHandler.foundPrinter(DiscoveredPrinter)
method will only be invoked on the
first occurrence.discoveryHandler
- a DiscoveryHandler
instance that is used to handle discovery events (e.g. found a printer, errors, discovery finished).DiscoveryException
- if an error occurs while starting the discoverypublic static void findPrinters(DiscoveryHandler discoveryHandler) throws DiscoveryException
DiscoveryHandler.foundPrinter(DiscoveredPrinter)
method for each printer that is found during discovery.
DiscoveryHandler.discoveryFinished()
will be invoked when the discovery is finished and DiscoveryHandler.discoveryError(String)
will be
invoked when any errors are encountered during discovery. When DiscoveryHandler.discoveryError(String)
is invoked, the discovery will be canceled and
DiscoveryHandler.discoveryFinished()
will not be invoked.DiscoveryHandler.foundPrinter(DiscoveredPrinter)
method will only be invoked on the
first occurrence. discoveryHandler
- a DiscoveryHandler
instance that is used to handle discovery events (e.g. found a printer, errors, discovery finished).DiscoveryException
- if an error occurs while starting the discovery (errors during discovery will be sent via
DiscoveryHandler.discoveryError(String)
).public static void findPrinters(DiscoveryHandler discoveryHandler, java.util.List<String> printersToFind) throws DiscoveryException
printersToFind
. This method will invoke the
DiscoveryHandler.foundPrinter(DiscoveredPrinter)
method for each printer that is found during discovery. DiscoveryHandler.discoveryFinished()
will be invoked when the discovery is finished and DiscoveryHandler.discoveryError(String)
will be invoked when any errors are encountered during
discovery. DiscoveryHandler.foundPrinter(DiscoveredPrinter)
method will only be invoked on the
first occurrence.discoveryHandler
- a DiscoveryHandler
instance that is used to handle discovery events (e.g. found a printer, errors, discovery finished).printersToFind
- a list of IP addresses or DNS names for the printers to be discovered.DiscoveryException
- if an error occurs while starting the discovery (errors during discovery will be sent via
DiscoveryHandler.discoveryError(String)
).
© 2016 ZIH Corp. All Rights Reserved.