When in Iterator mode, the TCP 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:
The in and out objects can be used to read and write data to or from the TCP connection. For example, you can do the following to implement a simple echo server (put the code in the After GetNext Hook):
var ins = conn.getProperty("in"); var outs = conn.getProperty("out"); var str = ins.readLine(); outs.write("You said==>"+str+"<=="); outs.flush();
Because you are using a BufferedWriter, it is important to call the out.flush() method to make sure data is actually sent out over the connection.
If you specify a Parser, then the BufferedReader is passed to the Parser, which in turn reads and interprets data sent on the stream. The returned entry then includes any attributes assigned by the Parser as well as the properties listed previously (socket, in, and out).
If the TCP Connector is configured in Listen Mode=true then the connection is closed between each call to the getnext method. If Listen Mode=false the connection to the remote host is kept open for as long as the TCP Connector is active (for example, until the AssemblyLine stops).
The Listen Mode parameter in this connector should not be confused with the behavior of the TCP Server Connector, which is a connector more suited for accepting incoming (multiple concurrent ones, if necessary) TCP requests. The functionality associated with Listen Mode=true is deprecated and will be removed in future versions of the connector, and it will be possible to configure and use the connector for outgoing connections only.
When the TCP Connector works in this mode, the default implementation is to write entries in their string form, which is not useful. Typically, you specify a Parser or use the Override Add hook to preform specific output. In the Override Add hook you access the in or out objects by calling the Connector Interface's getReader() and getWriter() methods, for example:
var in = mytcpconnector.connector.getReader(); var out = mytcpconnector.connector.getWriter();
You can also use the Before Add and After Add hooks to insert headers or footers around the output from your Parser.
You can select a Parser for this Connector from the Parser pane, where you select a parser by clicking the top-left Select Parser button.
File system Connector,
Direct TCP /URL scripting,
TCP Server Connector