Go to the latest version of this document.

# ``twisted`.`internet`.`tcp`.`BaseClient``

class documentation

`class BaseClient(_BaseBaseClient, _TLSClientMixin, Connection): (source)`

Known subclasses: `twisted.internet.tcp.Client`, `twisted.internet.unix.Client`

Constructor: `BaseClient(skt, protocol, reactor)`

View In Hierarchy

A base class for client TCP (and similar) sockets.

Method | `createInternetSocket` | (internal) Create a non-blocking socket using self.addressFamily, self.socketType.
Method | `doConnect` | Initiate the outgoing connection attempt.
Instance Variable | `connected` | Undocumented
Instance Variable | `logstr` | Undocumented
Instance Variable | `protocol` | Undocumented
Instance Variable | `realAddress` | The address object that will be used for socket.connect; this address is an address tuple (the number of elements dependent upon the address family) which does not contain any names which need to be resolved.
Method | `_collectSocketDetails` | Clean up references to the socket and its file descriptor.
Method | `_connectDone` | This is a hook for when a connection attempt has succeeded.
Method | `_stopReadingAndWriting` | Implement the POSIX-ish (i.e. `twisted.internet.interfaces.IReactorFDSet`) method of detaching this socket from the reactor for `_BaseBaseClient`.
Instance Variable | `_base` | `Connection`, which is the base class of this class which has all of the useful file descriptor methods. This is used by `_TLSServerMixin` to call the right methods to directly manipulate the transport, as is necessary for writing TLS-encrypted bytes (whereas those methods on ...

Inherited from `_BaseBaseClient`:

Method | `connectionLost` | Invoked by lower-level logic when it's time to clean the socket up. Depending on the state of the connection, either inform the attached `Connector` that the connection attempt has failed, or inform the connected ...
Method | `failIfNotConnected` | Generic method called when the attempts to connect failed. It basically cleans everything it can: call connectionFailed, stop read and write, delete socket related members.
Method | `resolveAddress` | Resolve the name that was passed to this `_BaseBaseClient`, if necessary, and then move on to attempting the connection once an address has been determined. (The connection will be attempted immediately within this function if either name resolution can be synchronous or the address was an IP address literal...
Method | `stopConnecting` | If a connection attempt is still outstanding (i.e. no connection is yet established), immediately stop attempting to connect.
Instance Variable | `addressFamily` | The address family constant (`socket.AF_INET`, `socket.AF_INET6`, `socket.AF_UNIX`) of the underlying socket of this client connection.
Instance Variable | `reactor` | The class pointed to by `_commonConnection` should set this attribute in its constructor.
Instance Variable | `socketType` | The socket type constant (`socket.SOCK_STREAM` or `socket.SOCK_DGRAM`) of the underlying socket.
Method | `_finishInit` | Called by subclasses to continue to the stage of initialization where the socket connect attempt is made.
Method | `_setRealAddress` | Set the resolved address of this `_BaseBaseClient` and initiate the connection attempt.
Class Variable | `_commonConnection` | Subclasses must provide this attribute, which indicates the `Connection`-alike class to invoke `__init__` and `connectionLost` on.
Instance Variable | `_closeSocket` | Subclasses must implement in order to close the socket in response to a terminated connection attempt.
Instance Variable | `_requiresResolution` | A flag indicating whether the address of this client will require name resolution. `True` if the hostname of said address indicates a name that must be resolved by hostname lookup, `False` if it indicates an IP address literal.

Inherited from `ClientMixin` (via `_BaseBaseClient`):

Instance Variable | `_tlsClientDefault` | Always `True`, indicating that this is a client connection, and by default when TLS is negotiated this class will act as a TLS client.

Inherited from `Connection` (via `_BaseBaseClient`, `ClientMixin`):

Method | `__init__` | No summary
Method | `doRead` | Calls self.protocol.dataReceived with all available data.
Method | `getHandle` | Return the socket for this connection.
Method | `getTcpKeepAlive` | Return if `SO_KEEPALIVE` is enabled.
Method | `getTcpNoDelay` | Return if `TCP_NODELAY` is enabled.
Method | `logPrefix` | Return the prefix to log with when I own the logging thread.
Method | `readConnectionLost` | Indicates read connection was lost.
Method | `setTcpKeepAlive` | Enable/disable `SO_KEEPALIVE`.
Method | `setTcpNoDelay` | Enable/disable `TCP_NODELAY`.
Method | `writeSomeData` | Write as much as possible of the given data to this TCP connection.
Instance Variable | `socket` | Undocumented
Method | `_closeWriteConnection` | Undocumented
Method | `_dataReceived` | Undocumented

Inherited from `ConnectionMixin` (via `_BaseBaseClient`, `ClientMixin`, `Connection`):

Method | `loseConnection` | Close this connection after writing all pending data.
Method | `registerProducer` | Register a producer.
Method | `startTLS` | No summary
Method | `unregisterProducer` | Unregister a producer.
Method | `write` | Write some bytes to this connection, passing them through a TLS layer if necessary, or discarding them if the connection has already been lost.
Method | `writeSequence` | Write some bytes to this connection, scatter/gather-style, passing them through a TLS layer if necessary, or discarding them if the connection has already been lost.
Constant | `TLS` | A flag indicating whether TLS is currently in use on this transport. This is not a good way for applications to check for TLS, instead use `twisted.internet.interfaces.ISSLTransport`.

Inherited from `FileDescriptor` (via `_BaseBaseClient`, `ClientMixin`, `Connection`, `ConnectionMixin`):

Method | `doWrite` | Called when data can be written.
Method | `fileno` | File Descriptor number for select().
Method | `getHost` | Similar to getPeer, but returns an address describing this side of the connection.
Method | `getPeer` | Get the remote address of this connection.
Method | `loseWriteConnection` | Undocumented
Method | `pauseProducing` | Pause producing data.
Method | `resumeProducing` | Resume producing data.
Method | `startReading` | Start waiting for read availability.
Method | `startWriting` | Start waiting for write availability.
Method | `stopConsuming` | Stop consuming data.
Method | `stopProducing` | Stop producing data.
Method | `stopReading` | Stop waiting for read availability.
Method | `stopWriting` | Stop waiting for write availability.
Method | `writeConnectionLost` | Indicates write connection was lost.
Constant | `SEND_LIMIT` | Undocumented
Class Variable | `bufferSize` | Undocumented
Class Variable | `disconnecting` | Undocumented
Instance Variable | `dataBuffer` | Undocumented
Instance Variable | `disconnected` | Undocumented
Instance Variable | `offset` | Undocumented
Instance Variable | `producer` | Undocumented
Instance Variable | `producerPaused` | Undocumented
Method | `_isSendBufferFull` | Determine whether the user-space send buffer for this transport is full or not.
Method | `_maybePauseProducer` | Possibly pause a producer, if there is one and the send buffer is full.
Method | `_postLoseConnection` | Called after a loseConnection(), when all data has been written.
Class Variable | `_writeDisconnected` | Undocumented
Instance Variable | `_tempDataBuffer` | Undocumented
Instance Variable | `_tempDataLen` | Undocumented
Instance Variable | `_writeDisconnecting` | Undocumented

Inherited from `_ConsumerMixin` (via `_BaseBaseClient`, `ClientMixin`, `Connection`, `ConnectionMixin`, `FileDescriptor`):

Instance Variable | `streamingProducer` | `bool` or `int`

Inherited from `_LogOwner` (via `_BaseBaseClient`, `ClientMixin`, `Connection`, `ConnectionMixin`, `FileDescriptor`, `_ConsumerMixin`):

Method | `_getLogPrefix` | Determine the log prefix to use for messages related to `applicationObject`, which may or may not be an `interfaces.ILoggingContext` provider.

Inherited from `_SocketCloser` (via `_BaseBaseClient`, `ClientMixin`, `Connection`, `ConnectionMixin`, `FileDescriptor`, `_ConsumerMixin`, `_LogOwner`):

Instance Variable | `_shouldShutdown` | Set to `True` if `shutdown` should be called before calling `close` on the underlying socket.

Inherited from `_AbortingMixin` (via `_BaseBaseClient`, `ClientMixin`, `Connection`, `ConnectionMixin`, `FileDescriptor`, `_ConsumerMixin`, `_LogOwner`, `_SocketCloser`):

Method | `abortConnection` | Aborts the connection immediately, dropping any buffered data.
Instance Variable | `_aborting` | Set to `True` when `abortConnection` is called.

def createInternetSocket(self): (source)

(internal) Create a non-blocking socket using self.addressFamily, self.socketType.

def doConnect(self): (source)

Initiate the outgoing connection attempt.

Note
Applications do not need to call this method; it will be invoked internally as part of `IReactorTCP.connectTCP`.

connected: `int` = (source)
overrides `twisted.internet.abstract.FileDescriptor.connected`

Undocumented

logstr = (source)
overrides `twisted.internet.tcp.Connection.logstr`

Undocumented

protocol = (source)
overrides `twisted.internet.tcp.Connection.protocol`

Undocumented

realAddress: `tuple` = (source)
overrides `twisted.internet.tcp._BaseBaseClient.realAddress`
overridden in `twisted.internet.unix.Client`

The address object that will be used for socket.connect; this address is an address tuple (the number of elements dependent upon the address family) which does not contain any names which need to be resolved.

def _collectSocketDetails(self): (source)
overrides `twisted.internet.tcp._BaseBaseClient._collectSocketDetails`

Clean up references to the socket and its file descriptor.

See Also
`_BaseBaseClient`

def _connectDone(self): (source)
overridden in `twisted.internet.ssl.Client`

This is a hook for when a connection attempt has succeeded.

Here, we build the protocol from the `twisted.internet.protocol.ClientFactory` that was passed in, compute a log string, begin reading so as to send traffic to the newly built protocol, and finally hook up the protocol itself.

This hook is overridden by `ssl.Client` to initiate the TLS protocol.

def _stopReadingAndWriting(self): (source)
overrides `twisted.internet.tcp._BaseBaseClient._stopReadingAndWriting`

Implement the POSIX-ish (i.e. `twisted.internet.interfaces.IReactorFDSet`) method of detaching this socket from the reactor for `_BaseBaseClient`.

_base = (source)

`Connection`, which is the base class of this class which has all of the useful file descriptor methods. This is used by `_TLSServerMixin` to call the right methods to directly manipulate the transport, as is necessary for writing TLS-encrypted bytes (whereas those methods on `Server` will go through another layer of TLS if it has been enabled).