April 2024 - This site, and Kamaelia are being updated. There is significant work needed, and PRs are welcome.


Simple Threaded TCP Client

This component is for making a TCP connection to a server. Send to its "inbox" inbox to send data to the server. Pick up data received from the server on its "outbox" outbox.

This component runs in its own separate thread so it can block on the socket connection. This was written because some platforms that don't support non-blocking calls to read/write data from sockets (eg. Python for Nokia Series-60).

Example Usage

Sending the contents of a file to a server at address on port 1000:

Pipeline( RateControlledFileReader("myfile", rate=100000),
          ThreadedTCPClient("", 1000),

How does it work?

The component opens a socket connection to the specified server on the specified port. Data received over the connection appears at the component's "outbox" outbox as strings. Data can be sent as strings by sending it to the "inbox" inbox.

The component will shutdown in response to a producerFinished message arriving on its "control" inbox. The socket will be closed, and a socketShutdown message will be sent to the "signal" outbox.

All socket errors exceptions are passed on out of the "signal" outbox. This will always result in the socket being closed (if open) and a socketShutdown message also being sent to the "signal" outbox (after the exception).

It does not use a ConnectedSocketAdapter, instead handling all socket communications itself.

The compnent is based on Axon.ThreadedComponent.threadedcomponent


class ThreadedTCPClient(Axon.ThreadedComponent.threadedcomponent)

ThreadedTCPClient(host,port[,chargen][,initalsendmessage]) -> threaded component with a TCP connection to a server.

Establishes a TCP connection to the specified server.

Keyword arguments:

  • host -- address of the server to connect to (string)
  • port -- port number to connect on
  • initialsendmessage -- to be send immediately after connection is established (default=None)


  • control :
  • inbox : data to send to the socket


  • outbox : data received from the socket
  • signal : diagnostic output, errors and shutdown messages

Methods defined here


You should be using the inbox/outbox interface, not these methods (except construction). This documentation is designed as a roadmap as to their functionalilty for maintainers and new component developers.

__init__(self, host, port[, chargen][, initialsendmessage])

x.__init__(...) initializes x; see x.__class__.__doc__ for signature


Main (thread) loop


Got a problem with the documentation? Something unclear that could be clearer? Want to help improve it? Constructive criticism is very welcome - especially if you can suggest a better rewording!

Please leave you feedback here in reply to the documentation thread in the Kamaelia blog.

-- Automatic documentation generator, 05 Jun 2009 at 03:01:38 UTC/GMT