t.i.e.clientFromString(reactor, description) : function documentation

Part of twisted.internet.endpoints View Source

Construct a client endpoint from a description string.

Client description strings are much like server description strings, although they take all of their arguments as keywords, aside from host and port.

You can create a TCP client endpoint with the 'host' and 'port' arguments, like so:

   clientFromString(reactor, b"tcp:host=www.example.com:port=80")

or, without specifying host and port keywords:

   clientFromString(reactor, b"tcp:www.example.com:80")

Or you can specify only one or the other, as in the following 2 examples:

   clientFromString(reactor, b"tcp:host=www.example.com:80")
   clientFromString(reactor, b"tcp:www.example.com:port=80")

or an SSL client endpoint with those arguments, plus the arguments used by the server SSL, for a client certificate:

   clientFromString(reactor, b"ssl:web.example.com:443:"

to specify your certificate trust roots, you can identify a directory with PEM files in it with the caCertsDir argument:

   clientFromString(reactor, b"ssl:host=web.example.com:port=443:"

Both TCP and SSL client endpoint description strings can include a 'bindAddress' keyword argument, whose value should be a local IPv4 address. This fixes the client socket to that IP address:

   clientFromString(reactor, b"tcp:www.example.com:80:"

NB: Fixed client ports are not currently supported in TCP or SSL client endpoints. The client socket will always use an ephemeral port assigned by the operating system

You can create a UNIX client endpoint with the 'path' argument and optional 'lockfile' and 'timeout' arguments:

       reactor, b"unix:path=/var/foo/bar:lockfile=1:timeout=9")

or, with the path as a positional argument with or without optional arguments as in the following 2 examples:

   clientFromString(reactor, b"unix:/var/foo/bar")
   clientFromString(reactor, b"unix:/var/foo/bar:lockfile=1:timeout=9")

This function is also extensible; new endpoint types may be registered as IStreamClientEndpointStringParserWithReactor plugins. See that interface for more information.

ParametersreactorThe client endpoint will be constructed with this reactor.
descriptionThe strports description to parse. (type: bytes)
ReturnsA new endpoint which can be used to connect with the parameters given by by description. (type: IStreamClientEndpoint)
Present Since10.2
API Documentation for Twisted, generated by pydoctor at 2014-05-12 18:27:00.