Package com.zebra.sdk.comm
Class TlsStatusConnection
Object
com.zebra.sdk.comm.ConnectionA
com.zebra.sdk.comm.TlsConnection
com.zebra.sdk.comm.TlsStatusConnection
- All Implemented Interfaces:
Connection,ConnectionWithWriteLogging,com.zebra.sdk.comm.internal.ConnectionI,IpAddressable,StatusConnection,StatusConnectionWithWriteLogging
Establishes a status only 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.TlsConfig;
import com.zebra.sdk.comm.TlsStatusConnection;
import com.zebra.sdk.printer.SGD;
public class TlsStatusConnectionExample {
public static void main(String[] args) throws Exception {
new TlsStatusConnectionExample().sendJSONOverStatusChannel("1.2.3.4");
}
private void sendJSONOverStatusChannel(String theIpAddress) throws ConnectionException {
// Instantiate connection for ZPL TCP port at given address
Connection thePrinterConn = new TlsStatusConnection(theIpAddress, TlsStatusConnection.DEFAULT_STATUS_TLS_PORT, TlsConfig.trustAll());
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe default Status TLS port for ZPL devices.Fields inherited from class com.zebra.sdk.comm.TlsConnection
DEFAULT_TLS_PORT -
Constructor Summary
ConstructorsConstructorDescriptionTlsStatusConnection(String address, int port, TlsConfig tlsConfig) Initializes a new status only instance of theTlsConnectionclass.TlsStatusConnection(String address, int port, TlsConfig tlsConfig, int maxTimeoutForRead, int timeToWaitForMoreData) Initializes a new status only instance of theTlsConnectionclass.TlsStatusConnection(String address, TlsConfig tlsConfig) Initializes a new status only instance of theTlsStatusConnectionclass using the default status port of9243. -
Method Summary
Modifier and TypeMethodDescriptionReturn the IP address and the status port as the description.toString()ReturnsTLS_STATUS:[address]:[port number].
Theaddressandport numberare the parameters which were passed into the constructor.Methods inherited from class com.zebra.sdk.comm.TlsConnection
getAddress, getConnectionReestablisher, getPortNumber, getTlsConfig, sendAndWaitForResponse, sendAndWaitForResponse, sendAndWaitForValidResponse, sendAndWaitForValidResponseMethods inherited from class com.zebra.sdk.comm.ConnectionA
addWriteLogStream, bytesAvailable, close, getManufacturer, getMaxDataToWrite, getMaxTimeoutForRead, getTimeToWaitForMoreData, isConnected, open, read, read, read, read, readChar, setMaxDataToWrite, setMaxTimeoutForRead, setReadTimeout, setTimeToWaitForMoreData, waitForData, write, write, writeMethods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface com.zebra.sdk.comm.Connection
bytesAvailable, close, getConnectionReestablisher, getMaxTimeoutForRead, getTimeToWaitForMoreData, isConnected, open, read, read, readChar, sendAndWaitForResponse, sendAndWaitForResponse, sendAndWaitForValidResponse, sendAndWaitForValidResponse, setMaxTimeoutForRead, setTimeToWaitForMoreData, waitForData, write, write, writeMethods inherited from interface com.zebra.sdk.comm.internal.ConnectionI
getManufacturer, getMaxDataToWrite, read, read, setMaxDataToWrite, setReadTimeoutMethods inherited from interface com.zebra.sdk.comm.StatusConnectionWithWriteLogging
addWriteLogStream
-
Field Details
-
DEFAULT_STATUS_TLS_PORT
public static final int DEFAULT_STATUS_TLS_PORTThe default Status TLS port for ZPL devices.- See Also:
-
-
Constructor Details
-
TlsStatusConnection
Initializes a new status only instance of theTlsStatusConnectionclass using the default status port of9243. This constructor will use the default timeouts forConnection.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:
TlsStatusConnection(String, int, TlsConfig, int, int).- Parameters:
address- the IP Address or DNS Hostname.tlsConfig- TLS configuration including certificates and protocols.
-
TlsStatusConnection
Initializes a new status only instance of theTlsConnectionclass. This constructor will use the default timeouts forConnection.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:
TlsStatusConnection(String, int, TlsConfig).- Parameters:
address- the IP Address or DNS Hostname.port- the port number.tlsConfig- TLS configuration including certificates and protocols.
-
TlsStatusConnection
public TlsStatusConnection(String address, int port, TlsConfig tlsConfig, int maxTimeoutForRead, int timeToWaitForMoreData) Initializes a new status only instance of theTlsConnectionclass. This constructor will use the specified timeouts forConnection.read(). The timeout is a maximum ofmaxTimeoutForReadmilliseconds for any data to be received. If no more data is available aftertimeToWaitForMoreDatamilliseconds the read operation is assumed to be complete.- Parameters:
address- the IP Address or DNS Hostname.port- the 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.
-
-
Method Details
-
toString
ReturnsTLS_STATUS:[address]:[port number].
Theaddressandport numberare the parameters which were passed into the constructor.- Specified by:
toStringin interfaceConnection- Overrides:
toStringin classTlsConnection- Returns:
- the connection description string.
- See Also:
-
getSimpleConnectionName
Return the IP address and the status port as the description.- Specified by:
getSimpleConnectionNamein interfaceConnection- Overrides:
getSimpleConnectionNamein classTlsConnection- Returns:
- a human-readable description of the connection.
- See Also:
-