Extensible Common Data Adapter: Reading from and Writing to Sockets

<< Click to Display Table of Contents >>

Navigation:  »No topics above this level«

Extensible Common Data Adapter: Reading from and Writing to Sockets

Return to chapter overview

Configured for a socket, the Extensible Common Data Adapter (ECDA)  reads or writes data streamed from a client program using TCP or UDP. The adapter listens or inserts at a configurable port awaiting client connections. Incoming packets are streamed as described below.

Implementing the Extensible Common Data Adapter for Sockets

You configure the Extensible Common Data Adapter to read or write over sockets using server options and foreign table/stream options. You reference the library com.sqlstream.plugin.common.SocketColumnSet, as in the following code:

CREATE OR REPLACE SERVER "NetWriterServer"

FOREIGN DATA WRAPPER "NetWriterWrapper"

OPTIONS (classname 'com.sqlstream.plugin.common.SocketColumnSet')

 

Next, you create a foreign stream object. This object contains connection information for the socket, such as format type, port, character encoding, whether or not to write a header, and the host name. Streams, like most SQL objects (but unlike data wrappers and servers), should be created within a schema. The following code first creates a schema in which to run the rest of the sample code below, then creates a foreign stream named "NetWriterStream."

CREATE OR REPLACE SCHEMA "SOCKETWRITER"

SET SCHEMA 'SOCKETWRITER'

CREATE OR REPLACE FOREIGN STREAM "NetWriterStream"

("STR1" VARCHAR(32))

SERVER "NetWriterServer"

OPTIONS

(format_type 'CSV',

remote_port '5651',

character_encoding 'UTF-8',

write_header 'FALSE',

remote_host 'localhost')

 

A foreign stream that reads from a socket would look like the following:

CREATE OR REPLACE FOREIGN STREAM "NetReaderStream"

("STR1" VARCHAR(32))

SERVER "NetReaderServer"

OPTIONS

(format_type 'CSV',

remote_port '5601',

character_encoding 'UTF-8',

remote_host 'localhost',

skip_header 'false');

Foreign Stream or Table Options for Sockets

Name

Description

Possible Values

IS_IPV6

Whether or not the socket uses IPV6.


IS_TCP

Whether or not the socket uses TCP.


REMOTE_HOST

Specifies which interface to listen to. It defaults to all interfaces. You can override this to 'LOCALHOST' to listen to only local connections, or a specific ip address, such as <168.212.226.204>.

myhost.com

REMOTE_PORT

Internet socket port number, that is, the port number at which a Foreign Stream will accept connections.

5561

SERVER_HOST

Specifies which interface to listen to. It defaults to all interfaces. You can override this to 'LOCALHOST' to listen to only local connections, or a specific ip address, such as <168.212.226.204>.


SERVER_PORT

Specifies which port to listen to.


SKIP_HEADER

Omits header for files written.


Additional Columns Generated for Sockets

The following columns may be auto generated by the file adapter if you are doing a select, that is, reading from the file.

Column

Meaning

SOURCE_HOST

Remote host from which this row was read.

SOURCE_PORT

Remote port from which this row was read.