Client and backend. This class is shared: the same code is compiled into your app and into your server, so everything on this page works in both.

public abstract class SqlSocket

  1. Object
  2. SqlSocket

A connection to a database server, as the wire clients in this package see it.

Each target opens one its own way – the backend over its own sockets, an application over the port’s – and hands it over through SqlPlatform.connect(String, int, int). A target that cannot run TLS refuses the TLS calls: a client asked for TLS fails to connect, it never continues in the clear.

Constructors

public SqlSocket()

Methods

public abstract int read(byte[] buffer, int offset, int length) throws IOExceptionReads at most length bytes, blocking until at least one arrives.
public abstract void write(byte[] buffer, int offset, int length) throws IOExceptionWrites all length bytes.
public abstract void setReadTimeout(int millis) throws IOExceptionHow long a read may block before it fails, in milliseconds; 0 waits forever.
public abstract void startTls(String host, String caFile, boolean verifyHost, String alpn) throws IOExceptionUpgrades the connection to TLS in place, verifying the server’s certificate against caFile (or the platform’s trust roots when it is null) and, when verifyHost is set, its name against host.
public abstract void startTlsTunnelled(String host, String caFile, boolean verifyHost, int packetType) throws IOExceptionUpgrades to TLS with the handshake carried inside the protocol’s own packets of type packetType (SQL Server’s PRELOGIN); after the handshake the connection is ordinary TLS.
public void startTls(String host, String caFile, boolean verifyHost) throws IOExceptionUpgrades to TLS with no protocol offered; see startTls(String, String, boolean, String).
public abstract void close()Closes the connection; closing twice does nothing.

Inherited methods

Constructor details

SqlSocket

public SqlSocket()

Method details

read

public abstract int read(byte[] buffer, int offset, int length) throws IOException
Reads at most length bytes, blocking until at least one arrives.

Returns

the number of bytes read, or -1 at the end of the stream

write

public abstract void write(byte[] buffer, int offset, int length) throws IOException
Writes all length bytes.

setReadTimeout

public abstract void setReadTimeout(int millis) throws IOException
How long a read may block before it fails, in milliseconds; 0 waits forever.

startTls

public abstract void startTls(String host, String caFile, boolean verifyHost, String alpn) throws IOException
Upgrades the connection to TLS in place, verifying the server’s certificate against caFile (or the platform’s trust roots when it is null) and, when verifyHost is set, its name against host. alpn is the protocol to offer, or null for none.

startTlsTunnelled

public abstract void startTlsTunnelled(String host, String caFile, boolean verifyHost, int packetType) throws IOException
Upgrades to TLS with the handshake carried inside the protocol’s own packets of type packetType (SQL Server’s PRELOGIN); after the handshake the connection is ordinary TLS.

startTls

public void startTls(String host, String caFile, boolean verifyHost) throws IOException
Upgrades to TLS with no protocol offered; see startTls(String, String, boolean, String).

close

public abstract void close()
Closes the connection; closing twice does nothing.