public class RemoteDiscoverer extends Object
NetworkDiscoverer
package test.zebra.sdk.comm.examples;
import java.util.List;
import com.zebra.sdk.comm.Connection;
import com.zebra.sdk.comm.ConnectionException;
import com.zebra.sdk.printer.ZebraPrinter;
import com.zebra.sdk.printer.ZebraPrinterFactory;
import com.zebra.sdk.printer.ZebraPrinterLanguageUnknownException;
import com.zebra.sdk.printer.discovery.DiscoveredPrinter;
import com.zebra.sdk.remote.comm.RemoteConnection;
import com.zebra.sdk.remote.discovery.RemoteDiscoverer;
public class RemoteDiscovererExample {
// This example assumes Link-OS printers are connected via Web Sockets to a server which is running a Zebra servlet
// instance.
public static void main(String[] args) throws Exception {
new RemoteDiscovererExample().listRemotePrinters();
new RemoteDiscovererExample().printConfigLabelUsingDnsName("myPrinterUUID");
}
private void listRemotePrinters() {
try {
List<DiscoveredPrinter> connectedPrinters = RemoteDiscoverer.getConnectedPrinters();
for (DiscoveredPrinter p : connectedPrinters) {
String serialNumber = p.getDiscoveryDataMap().get("SERIAL_NUMBER");
System.out.println("Serial number " + serialNumber);
}
} catch (ConnectionException e) {
e.printStackTrace();
}
}
private void printConfigLabelUsingDnsName(String theUniqueId) throws ConnectionException {
Connection connection = new RemoteConnection(theUniqueId);
try {
connection.open();
ZebraPrinter p = ZebraPrinterFactory.getInstance(connection);
p.printConfigurationLabel();
} catch (ConnectionException e) {
e.printStackTrace();
} catch (ZebraPrinterLanguageUnknownException e) {
e.printStackTrace();
} finally {
connection.close();
}
}
}
Modifier and Type | Method and Description |
---|---|
static List<DiscoveredPrinter> |
getConnectedPrinters()
Returns a list of remotely connected Zebra printers.
|
static List<DiscoveredPrinter> |
getConnectedPrinters(int rmiServerPort)
Returns a list of remotely connected Zebra printers.
|
static void |
registerForConnections(ConnectionHandlerI connectionHandler,
int rmiServerPort)
Register for connection events from the Zebra Weblink servlet.
|
public static List<DiscoveredPrinter> getConnectedPrinters() throws ConnectionException
ConnectionException
- if there is a problem connecting to the Zebra Weblink servlet.RemoteDiscoverer.getConnectedPrinters(int rmiServerPort)
if your servlet is running on a different
port.
public static List<DiscoveredPrinter> getConnectedPrinters(int rmiServerPort) throws ConnectionException
rmiServerPort
.rmiServerPort
- the port the RMI server is running on.ConnectionException
- if there is a problem connecting to the Zebra Weblink servlet.public static void registerForConnections(ConnectionHandlerI connectionHandler, int rmiServerPort) throws ConnectionException
connectionHandler
- callback to receive connection events.rmiServerPort
- the port the RMI server is running on.ConnectionException
- if there is a problem connecting to the Zebra Weblink servlet.
© 2016 ZIH Corp. All Rights Reserved.