Metamerge logo
Search

Advanced Search
*
*
*
* HOME DOCUMENTS & RESOURCES DOWNLOADS EARLY TECH ACCESS SUPPORT FAQ KNOWN ISSUES OLD VERSIONS
*

 

TCP Connector

Overview

The TCPConnector is a transport Connector using TCP sockets for transport. You can only use the Connector in Iterator and AddOnly mode.

 Iterator Mode 

When using the Connector in Iterator mode the Connector waits for incoming TCP calls on a specific port. When a connection is established the getnext method returns an entry with the following properties:

  • socket The TCP socket object (e.g. the TCP input/output streams) 
  • in An instance of a BufferedReader using the socket's input stream 
  • out An instance of a BufferedWriter using the socket's output stream

The in and out objects can be used to read and write data from/to the TCP connection. For example, you can do the following to implement a simple echo server. Put the code in your after-getnext hook:

var in = conn.getProperty("in"); 
var out = conn.getProperty("out");
var str = in.readLine(); 
out.write ("You said: " + str + "\r\n"); 
out.flush();

Since you are using a BufferedWriter it is important to call the out.flush() method to make sure data is actually sent out on the connection.

If you specify a Parser then the BufferedReader will be passed to the Parser which in turn reads and interprets data sent on the stream. The returned entry will then include any attributes assigned by the Parser as well as the properties listed above.

If the Connector is configured in serverMode=true then the connection will be closed between each call to the getnext method. If serverMode=false the connection to the remote host will be kept open for as long as the Connector is active (e.g. until the AssemblyLine terminates).

 AddOnly Mode

When the Connector works in this mode the default implementation is to write entries in their string form which is not very useful. Typically, you will specify a Parser or use the override-add hook to do specific output. In the override-add hook you access the in/out objects by calling the raw-Connector's getReader() and getWriter() methods as in:

var in = mytcpconnector.connector.getReader(); 
var out = mytcpconnector.connector.getWriter();

You can also use the before-add and after-add hooks to insert headers/footers around the output from your Parser.

Configuration

Parameter

Description

serverMode  If true then Iterating will listen for incoming requests. If false then Iterating will connect to remote server.
tcpPort The TCP port number to connect or listen to (depends on servermode)
tcpHost The remote host to which connections are make (servermode = false)
parser The Parser used for reading/writing entries

See Also

File System Connector, URL Connector, Direct tcp/url scripting

 

 

 

 

*
  Metamerge Integrator version 4.6 ©Copyright Metamerge AS 2000-2002 Last edited 2002-06-10 contact us