com.taosdata.jdbc.ws

## Class Transport

- java.lang.Object
- - com.taosdata.jdbc.ws.Transport

All Implemented Interfaces:
  AutoCloseable

    public class Transport
    extends Object
    implements AutoCloseable

Handles message sending and receiving over WebSocket connections to TDengine. Provides synchronous and asynchronous message sending with timeout and retry support. Delegates connection management to WSConnectionManager.

### Field Summary

Fields
`static byte[]` `EMPTY_BYTE_ARRAY` Empty byte array constant
`static String` `ERROR_MSG_CONNECTION_CLOSED` Error message for closed connection
`static int` `TSDB_CODE_RPC_NETWORK_UNAVAIL` Error code indicating RPC network unavailability
`static int` `TSDB_CODE_RPC_SOMENODE_NOT_CONNECTED` Error code indicating some nodes are not connected

### Constructor Summary

Constructors
`protected` `Transport()` Protected constructor for internal use.
`` `Transport(WSFunction function, ConnectionParam param, InFlightRequest inFlightRequest)` Constructs a new Transport instance.

### Method Summary

All Methods Instance Methods Concrete Methods
`void` `balanceConnection()` Balances connections across available endpoints.
`void` `checkConnection(int connectTimeout)` Checks and establishes connection to TDengine servers.
`void` `close()` Closes this transport and releases all resources.
`ConnectionParam` `getConnectionParam()` Gets the connection parameters.
`Endpoint` `getCurrentEndpoint()` Gets the current active endpoint.
`int` `getReconnectCount()` Gets the number of reconnection attempts made.
`boolean` `isClosed()` Checks if this transport is closed.
`boolean` `isConnected()` Checks if the current connection is active.
`boolean` `isConnectionLost()` Checks if the current connection is lost.
`void` `reconnectTmq()` Performs TMQ-specific reconnection.
`Response` `send(Request request)` Sends a request with default timeout and retry enabled.
`Response` `send(Request request, boolean reSend, long timeout)` Sends a request with specified timeout and retry configuration.
`Response` `send(Request request, long timeout)` Sends a request with specified timeout and retry enabled.
`Response` `send(String action, long reqId, io.netty.buffer.ByteBuf buffer, boolean resend, long timeout)` Sends a request with pre-allocated ByteBuf buffer.
`Response` `send(String action, long reqId, long resultId, long type, byte[] rawData, byte[] rawData2, long timeout)` Sends a binary request with dual data payloads.
`Response` `send(String action, long reqId, long resultId, long type, byte[] rawData, long timeout)` Sends a binary request with single data payload.
`void` `sendFetchBlockAsync(long reqId, long resultId)` Sends asynchronous fetch block request.
`void` `sendWithoutResponse(Request request)` Sends a request without waiting for response.
`Response` `sendWithoutRetry(Request request, long timeout)` Sends a request without automatic retry on connection failure.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### TSDB_CODE_RPC_NETWORK_UNAVAIL

    public static final int TSDB_CODE_RPC_NETWORK_UNAVAIL

Error code indicating RPC network unavailability

See Also:
  Constant Field Values

#### TSDB_CODE_RPC_SOMENODE_NOT_CONNECTED

    public static final int TSDB_CODE_RPC_SOMENODE_NOT_CONNECTED

Error code indicating some nodes are not connected

See Also:
  Constant Field Values

#### EMPTY_BYTE_ARRAY

    public static final byte[] EMPTY_BYTE_ARRAY

Empty byte array constant

#### ERROR_MSG_CONNECTION_CLOSED

    public static final String ERROR_MSG_CONNECTION_CLOSED

Error message for closed connection

See Also:
  Constant Field Values

### Constructor Detail

#### Transport

    protected Transport()

Protected constructor for internal use.

#### Transport

    public Transport(WSFunction function,
                     ConnectionParam param,
                     InFlightRequest inFlightRequest)
              throws SQLException

Constructs a new Transport instance.

Parameters:
  `function` - the WebSocket function type
  `param` - the connection parameters
  `inFlightRequest` - the in-flight request manager
Throws:
  `SQLException` - if initialization fails

### Method Detail

#### send

    public Response send(Request request)
                  throws SQLException

Sends a request with default timeout and retry enabled.

Parameters:
  `request` - the request to send
Returns:
  the response from server
Throws:
  `SQLException` - if sending fails or timeout occurs

#### send

    public Response send(Request request,
                         long timeout)
                  throws SQLException

Sends a request with specified timeout and retry enabled.

Parameters:
  `request` - the request to send
  `timeout` - the timeout in milliseconds
Returns:
  the response from server
Throws:
  `SQLException` - if sending fails or timeout occurs

#### send

    public Response send(Request request,
                         boolean reSend,
                         long timeout)
                  throws SQLException

Sends a request with specified timeout and retry configuration.

Parameters:
  `request` - the request to send
  `reSend` - whether to retry on connection failure
  `timeout` - the timeout in milliseconds
Returns:
  the response from server
Throws:
  `SQLException` - if sending fails or timeout occurs

#### send

    public Response send(String action,
                         long reqId,
                         long resultId,
                         long type,
                         byte[] rawData,
                         long timeout)
                  throws SQLException

Sends a binary request with single data payload.

Parameters:
  `action` - the action type
  `reqId` - the request ID
  `resultId` - the result ID
  `type` - the message type
  `rawData` - the binary data payload
  `timeout` - the timeout in milliseconds
Returns:
  the response from server
Throws:
  `SQLException` - if sending fails or timeout occurs

#### send

    public Response send(String action,
                         long reqId,
                         long resultId,
                         long type,
                         byte[] rawData,
                         byte[] rawData2,
                         long timeout)
                  throws SQLException

Sends a binary request with dual data payloads.

Parameters:
  `action` - the action type
  `reqId` - the request ID
  `resultId` - the result ID
  `type` - the message type
  `rawData` - the first binary data payload
  `rawData2` - the second binary data payload
  `timeout` - the timeout in milliseconds
Returns:
  the response from server
Throws:
  `SQLException` - if sending fails or timeout occurs

#### sendFetchBlockAsync

    public void sendFetchBlockAsync(long reqId,
                                    long resultId)
                             throws SQLException

Sends asynchronous fetch block request.

Parameters:
  `reqId` - the request ID
  `resultId` - the result ID
Throws:
  `SQLException` - if sending fails

#### send

    public Response send(String action,
                         long reqId,
                         io.netty.buffer.ByteBuf buffer,
                         boolean resend,
                         long timeout)
                  throws SQLException

Sends a request with pre-allocated ByteBuf buffer.

Parameters:
  `action` - the action type
  `reqId` - the request ID
  `buffer` - the ByteBuf containing the request data
  `resend` - whether to retry on connection failure
  `timeout` - the timeout in milliseconds
Returns:
  the response from server
Throws:
  `SQLException` - if sending fails or timeout occurs

#### sendWithoutRetry

    public Response sendWithoutRetry(Request request,
                                     long timeout)
                              throws SQLException

Sends a request without automatic retry on connection failure.

Parameters:
  `request` - the request to send
  `timeout` - the timeout in milliseconds
Returns:
  the response from server
Throws:
  `SQLException` - if sending fails or timeout occurs

#### sendWithoutResponse

    public void sendWithoutResponse(Request request)
                             throws SQLException

Sends a request without waiting for response.

Parameters:
  `request` - the request to send
Throws:
  `SQLException` - if sending fails

#### isClosed

    public boolean isClosed()

Checks if this transport is closed.

Returns:
  true if closed, false otherwise

#### isConnectionLost

    public boolean isConnectionLost()

Checks if the current connection is lost.

Returns:
  true if connection is lost, false otherwise

#### close

    public void close()

Closes this transport and releases all resources.

Specified by:
  `close` in interface `AutoCloseable`

#### checkConnection

    public void checkConnection(int connectTimeout)
                         throws SQLException

Checks and establishes connection to TDengine servers.

Parameters:
  `connectTimeout` - the connection timeout in milliseconds
Throws:
  `SQLException` - if connection cannot be established within timeout

#### reconnectTmq

    public void reconnectTmq()
                      throws SQLException

Performs TMQ-specific reconnection.

Throws:
  `SQLException` - if reconnection fails

#### getReconnectCount

    public int getReconnectCount()

Gets the number of reconnection attempts made.

Returns:
  the reconnection count

#### isConnected

    public boolean isConnected()

Checks if the current connection is active.

Returns:
  true if connected, false otherwise

#### getConnectionParam

    public final ConnectionParam getConnectionParam()

Gets the connection parameters.

Returns:
  the connection parameters

#### getCurrentEndpoint

    public final Endpoint getCurrentEndpoint()

Gets the current active endpoint.

Returns:
  the current endpoint

#### balanceConnection

    public void balanceConnection()

Balances connections across available endpoints.

Throws:
  `SQLException` - if balance operation fails