Class MultichannelTlsConnection

Object
com.zebra.sdk.comm.MultichannelConnection
com.zebra.sdk.comm.MultichannelTlsConnection
All Implemented Interfaces:
Connection, ConnectionWithWriteLogging

public class MultichannelTlsConnection extends MultichannelConnection
Establishes a Multichannel TLS connection to a device

package test.zebra.sdk.comm.examples;
 
 import com.zebra.sdk.comm.Connection;
 import com.zebra.sdk.comm.ConnectionException;
 import com.zebra.sdk.comm.MultichannelTlsConnection;
 import com.zebra.sdk.comm.TlsConfig;
 import com.zebra.sdk.printer.PrinterStatus;
 import com.zebra.sdk.printer.ZebraPrinterFactory;
 import com.zebra.sdk.printer.ZebraPrinterLinkOs;
 
 public class MultichannelTlsConnectionExample {
 
     public static void main(String[] args) throws Exception {
         new MultichannelTlsConnectionExample().simpleExample("1.2.3.4");
         new MultichannelTlsConnectionExample().nonBlockingStatusReporting("1.2.3.4");
     }
 
     private void simpleExample(String theIpAddress) throws ConnectionException {
         // Instantiate Multichannel connection for simultaneous printing and status reporting at given address
         Connection thePrinterConn = new MultichannelTlsConnection(theIpAddress, MultichannelTlsConnection.DEFAULT_MULTICHANNEL_PRINTING_PORT, MultichannelTlsConnection.DEFAULT_MULTICHANNEL_STATUS_PORT, TlsConfig.trustAll());
 
         try {
             // Opens the connection - physical connection is established here.
             thePrinterConn.open();
 
             // Creates a Link-OS printing with the given connection
             ZebraPrinterLinkOs linkOsPrinter = ZebraPrinterFactory.getLinkOsPrinter(thePrinterConn);
 
             // This is sent over the printing channel (9100 by default)
             linkOsPrinter.printConfigurationLabel();
 
             // This is sent over the status channel (9200 by default)
             PrinterStatus status = linkOsPrinter.getCurrentStatus();
 
             System.out.println("The printer PAUSED state is : " + status.isPaused);
         } catch (ConnectionException e) {
             // Handle communications error here.
             e.printStackTrace();
         } finally {
             // Close the connection to release resources.
             thePrinterConn.close();
         }
     }
 
     private void nonBlockingStatusReporting(String theIpAddress) throws ConnectionException {
         // Instantiate Multichannel connection for simultaneous printing and status reporting at given address
         Connection thePrinterConn = new MultichannelTlsConnection(theIpAddress, MultichannelTlsConnection.DEFAULT_MULTICHANNEL_PRINTING_PORT, MultichannelTlsConnection.DEFAULT_MULTICHANNEL_STATUS_PORT, TlsConfig.trustAll());
 
         try {
             // Opens the connection - physical connection is established here.
             thePrinterConn.open();
 
             // Creates a Link-OS printing with the given connection
             ZebraPrinterLinkOs linkOsPrinter = ZebraPrinterFactory.getLinkOsPrinter(thePrinterConn);
 
             // This is sent over the printing channel (9100 by default) and will block the printing channel until the
             // label format is completely sent.
             String labelFormatStartCommand = "^XA";
             linkOsPrinter.sendCommand(labelFormatStartCommand);
 
             String labelBody = "^FO20,20^A0N,25,25^FDThis is a ZPL test.^FS";
             linkOsPrinter.sendCommand(labelBody);
 
             // This is sent over the status channel (9200 by default) and will return immediately even though the
             // printing channel is in use.
             // If a TlsConnection were used instead of a MultichannelTlsConnection, this would not be possible.
             PrinterStatus status = linkOsPrinter.getCurrentStatus();
 
             System.out.println("The printer PAUSED state is : " + status.isPaused);
 
             // Send the end of label command to finish and print the label.
             String labelFormatEndCommand = "^XZ";
             linkOsPrinter.sendCommand(labelFormatEndCommand);
         } catch (ConnectionException e) {
             // Handle communications error here.
             e.printStackTrace();
         } finally {
             // Close the connection to release resources.
             thePrinterConn.close();
         }
     }
 }
 
  • Field Details

    • DEFAULT_MULTICHANNEL_PRINTING_PORT

      public static final int DEFAULT_MULTICHANNEL_PRINTING_PORT
      The default Multichannel printing port for Link-OS devices.
      See Also:
    • DEFAULT_MULTICHANNEL_STATUS_PORT

      public static final int DEFAULT_MULTICHANNEL_STATUS_PORT
      The default Multichannel status port for Link-OS devices.
      See Also:
  • Constructor Details

    • MultichannelTlsConnection

      public MultichannelTlsConnection(String ipAddress, int printingPort, int statusPort, TlsConfig tlsConfig)
      Initializes a new instance of the MultichannelTlsConnection class. This constructor will use the default timeouts for Connection.read(). The default timeout is a maximum of 5 seconds for any data to be received. If no more data is available after 500 milliseconds the read operation is assumed to be complete.
      To specify timeouts other than the defaults, use:
      MultichannelTlsConnection(String, int, int, TlsConfig, int,int) or MultichannelTlsConnection(String, int, int, TlsConfig, int, int, int, int).
      Parameters:
      ipAddress - the IP Address or DNS Hostname.
      printingPort - the printing port number.
      statusPort - the status port number.
      tlsConfig - TLS configuration including certificates and protocols.
    • MultichannelTlsConnection

      public MultichannelTlsConnection(String ipAddress, int printingPort, int statusPort, TlsConfig tlsConfig, int maxTimeoutForRead, int timeToWaitForMoreData)
      Initializes a new instance of the MultichannelTlsConnection class. This constructor will use the specified timeouts for Connection.read() for both channels. The timeout is a maximum of maxTimeoutForRead milliseconds for any data to be received. If no more data is available after timeToWaitForMoreData milliseconds the read operation is assumed to be complete. If you wish to specify different timeouts for each channel, use MultichannelTlsConnection(String, int, int, TlsConfig, int, int, int, int).
      Parameters:
      ipAddress - the IP Address or DNS Hostname.
      printingPort - the printing port number.
      statusPort - the status port number.
      tlsConfig - TLS configuration including certificates and protocols.
      maxTimeoutForRead - the maximum time, in milliseconds, to wait for any data to be received.
      timeToWaitForMoreData - the maximum time, in milliseconds, to wait in-between reads after the initial read.
    • MultichannelTlsConnection

      public MultichannelTlsConnection(String ipAddress, int printingPort, int statusPort, TlsConfig tlsConfig, int printingChannelMaxTimeoutForRead, int printingChannelTimeToWaitForMoreData, int statusChannelMaxTimeoutForRead, int statusChannelTimeToWaitForMoreData)
      Initializes a new instance of the MultichannelTlsConnection class. This constructor will use the specified timeouts for Connection.read() for the channels. The timeout is a maximum of printingChannelMaxTimeoutForRead/statusChannelMaxTimeoutForRead milliseconds for any data to be received on the printing/status channels respectively. If no more data is available after printingChannelTimeToWaitForMoreData/statusChannelTimeToWaitForMoreData milliseconds on the printing/status channels respectively the read operation is assumed to be complete.
      Parameters:
      ipAddress - the IP Address or DNS Hostname.
      printingPort - the printing port number.
      statusPort - the status port number.
      tlsConfig - TLS configuration including certificates and protocols.
      printingChannelMaxTimeoutForRead - the maximum time, in milliseconds, to wait for any data to be received on the printing channel.
      printingChannelTimeToWaitForMoreData - the maximum time, in milliseconds, to wait in-between reads after the initial read on the printing channel.
      statusChannelMaxTimeoutForRead - the maximum time, in milliseconds, to wait for any data to be received on the status channel.
      statusChannelTimeToWaitForMoreData - the maximum time, in milliseconds, to wait in-between reads after the initial read on the status channel.
  • Method Details