Class TcpStatusConnection

All Implemented Interfaces:
Connection, ConnectionWithWriteLogging, com.zebra.sdk.comm.internal.ConnectionI, IpAddressable, StatusConnection, StatusConnectionWithWriteLogging

public class TcpStatusConnection extends TcpConnection implements StatusConnectionWithWriteLogging
Establishes a status only TCP 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.TcpStatusConnection;
 import com.zebra.sdk.printer.SGD;
 
 public class TcpStatusConnectionExample {
 
     public static void main(String[] args) throws Exception {
         new TcpStatusConnectionExample().sendJSONOverStatusChannel("1.2.3.4");
     }
 
     private void sendJSONOverStatusChannel(String theIpAddress) throws ConnectionException {
         // Instantiate connection for ZPL TCP port at given address
         Connection thePrinterConn = new TcpStatusConnection(theIpAddress, TcpStatusConnection.DEFAULT_STATUS_TCP_PORT);
 
         try {
             // Open the connection - physical connection is established here.
             thePrinterConn.open();
 
             // This sends down JSON to the status channel to retrieve the 'appl.name' setting
             String firmwareVersion = SGD.GET("appl.name", thePrinterConn);
 
             System.out.println("The firmware version is : " + firmwareVersion);
         } catch (ConnectionException e) {
             // Handle communications error here.
             e.printStackTrace();
         } finally {
             // Close the connection to release resources.
             thePrinterConn.close();
         }
     }
 }
 
  • Field Details

    • DEFAULT_STATUS_TCP_PORT

      public static final int DEFAULT_STATUS_TCP_PORT
      The default Status TCP port for ZPL devices.
      See Also:
  • Constructor Details

    • TcpStatusConnection

      public TcpStatusConnection(String address)
      Initializes a new status only instance of the TcpStatusConnection class using the default status port of 9200. 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:
      TcpStatusConnection(String, int, int, int).
      Parameters:
      address - the IP Address or DNS Hostname.
    • TcpStatusConnection

      public TcpStatusConnection(String address, int port)
      Initializes a new status only instance of the TcpConnection 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:
      TcpStatusConnection(String, int, int, int).
      Parameters:
      address - the IP Address or DNS Hostname.
      port - the port number.
    • TcpStatusConnection

      public TcpStatusConnection(String address, int port, int maxTimeoutForRead, int timeToWaitForMoreData)
      Initializes a new status only instance of the TcpConnection class. This constructor will use the specified timeouts for Connection.read(). 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.
      Parameters:
      address - the IP Address or DNS Hostname.
      port - the port number.
      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.
  • Method Details