public class TcpProtocol extends Protocol
This class is used for sending packets over a TCP connection to the Console.
It is used when the 'tcp' protocol is specified in the SmartInspect.setConnections(java.lang.String) connections string.
Please see the isValidOption method for a list of available protocol options.
Thread Safety: The public members of this class are threadsafe.
| Modifier and Type | Field and Description |
|---|---|
protected Formatter |
fFormatter |
protected String |
fHostName |
protected InputStream |
fIstream |
protected OutputStream |
fOstream |
protected int |
fPort |
protected int |
fTimeout |
fConnected| Constructor and Description |
|---|
TcpProtocol()
Creates and initializes a TcpProtocol instance.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
buildOptions(ConnectionsBuilder builder)
Overridden.
|
protected void |
doHandShake() |
protected String |
getName()
Overridden.
|
protected void |
internalConnect()
Overridden.
|
protected void |
internalDisconnect()
Overridden.
|
protected Socket |
internalInitializeSocket() |
protected void |
internalValidateWritePacketAnswer(int bytesRead,
byte[] answerBytes) |
protected void |
internalWritePacket(Packet packet)
Overridden.
|
protected boolean |
isValidOption(String name)
Validates if a protocol option is supported.
|
protected void |
loadOptions()
Overridden.
|
protected void |
readServerBanner() |
protected void |
sendClientBanner() |
addListener, composeLogHeaderPacket, connect, disconnect, dispatch, dispose, doError, failed, getAppName, getAsyncEnabledDefaultValue, getAsyncQueueDefaultValue, getBooleanOption, getBytesOption, getCaption, getHostName, getIntegerOption, getLevelOption, getReconnectDefaultValue, getRotateOption, getSizeOption, getStringOption, getTimespanOption, handleException, implConnect, implDisconnect, implDispatch, implWritePacket, initialize, internalDispatch, internalReconnect, internalWriteLogHeader, isAsynchronous, removeListener, reset, scheduleWritePacket, setAppName, setHostName, writePacketprotected InputStream fIstream
protected OutputStream fOstream
protected Formatter fFormatter
protected String fHostName
protected int fTimeout
protected int fPort
public TcpProtocol()
protected String getName()
protected boolean isValidOption(String name)
The following table lists all valid options, their default values and descriptions for the TCP protocol:
| Valid Options | Default Value | Description |
|---|---|---|
| host | "127.0.0.1" | Specifies the hostname where the Console is running |
| port | 4228 | Specifies the Console port |
| timeout | 30000 | Specifies the connect, receive and send timeout in milliseconds |
For further options which affect the behavior of this protocol, please have a look at the documentation of the Protocol.isValidOption method of the parent class. Example:
SiAuto.si.setConnections("tcp()");
SiAuto.si.setConnections("tcp(host=\\"localhost\\", port=4229)");
SiAuto.si.setConnections("tcp(timeout=2500)");
isValidOption in class Protocolname - The option name to validateprotected void buildOptions(ConnectionsBuilder builder)
buildOptions in class Protocolbuilder - The ConnectionsBuilder object to fill with the current options
of this protocolprotected void loadOptions()
This method loads all relevant options and ensures their correctness. See isValidOption for a list of options which are recognized by the TCP protocol
loadOptions in class Protocolprotected void doHandShake()
throws IOException,
SmartInspectException
IOExceptionSmartInspectExceptionprotected void readServerBanner()
throws SmartInspectException,
IOException
SmartInspectExceptionIOExceptionprotected void sendClientBanner()
throws IOException
IOExceptionprotected void internalConnect()
throws Exception
internalConnect in class ProtocolException - if creating or connecting the socket failedprotected Socket internalInitializeSocket() throws Exception
Exceptionprotected void internalWritePacket(Packet packet) throws Exception
This method sends the supplied packet to the SmartInspect Console and waits for a valid response.
internalWritePacket in class Protocolpacket - The packet to writeException - If sending the packet to the Console failedprotected void internalValidateWritePacketAnswer(int bytesRead,
byte[] answerBytes)
throws Exception
Exceptionprotected void internalDisconnect()
throws Exception
This method closes the underlying socket handle if previously created and disposes any supplemental objects.
internalDisconnect in class ProtocolException - If Closing the TCP socket failedCopyright © 2023. All rights reserved.