Implementing custom socket plug-ins

This section discusses how to plug a custom socket implementation into an application to customize the communication between a client and server. javax.net.ssl.SSLSocket is an example of a socket that you could customize to enable encryption.

com.sybase.jdbcx.SybSocketFactory is a Sybase extension interface that contains the createSocket(String, int, Properties) method that returns a java.net.Socket. To use a custom socket factory in jConnect, an application must implement this interface by defining the createSocket() method.

jConnect uses the new socket for its subsequent input/output operations. Classes that implement SybSocketFactory create sockets and provide a general framework for the addition of public socket-level functionality, as shown:

/**
 * Returns a socket connected to a ServerSocket on the named host,
 * at the given port.
 * @param host  the server host
 * @param port  the server port
 * @param props  Properties passed in through the connection
 * @returns Socket
 * @exception IOException, UnknownHostException
 */
public java.net.Socket createSocket(String host, int port, Properties props)
   throws IOException, UnknownHostException;

Passing in properties allows instances of SybSocketFactory to use connection properties to implement an intelligent socket.

When you implement SybSocketFactory to produce a socket, the same application code can use different kinds of sockets by passing the different kinds of factories or pseudo-factories that create sockets to the application.

You can customize factories with parameters used in socket construction. For example, you can customize factories to return sockets with different networking timeouts or security parameters already configured. The sockets returned to the application can be subclasses of java.net.Socket to directly expose new APIs for features such as compression, security, record marking, statistics collection, or firewall tunnelling (javax.net.SocketFactory).

NoteSybSocketFactory is intended to be an overly simplified javax.net.SocketFactory, enabling applications to bridge from java.net.* to javax.net.*

StepsUsing a custom socket with jConnect

  1. Provide a Java class that implements com.sybase.jdbcx.SybSocketFactory. See “Creating and configuring a custom socket”.

  2. Set the SYBSOCKET_FACTORY connection property so that jConnect can use your implementation to obtain a socket.

    To use a custom socket with jConnect, set the SYBSOCKET_FACTORY connection property to one of the following:

    See “Connection properties” for instructions on how to set SYBSOCKET_FACTORY.