Socket objects have the following methods. Except for makefile() these correspond to Unix system calls applicable to sockets.
(conn, address)
where conn is a new socket object usable to send and
receive data on the connection, and address is the address bound
to the socket on the other end of the connection.
connect(address)
, but return an error indicator
instead of raising an exception for errors returned by the C-level
connect() call (other problems, such as ``host not found,''
can still raise exceptions). The error indicator is 0
if the
operation succeeded, otherwise the value of the errno
variable. This is useful to support, for example, asynchronous connects.
Note:
This method has historically accepted a pair of
parameters for AF_INET addresses instead of only a tuple.
This was never intentional and is no longer be available in Python
2.0 and later.
(string, address)
where string is a string
representing the data received and address is the address of the
socket sending the data. The optional flags argument has the
same meaning as for recv() above.
(The format of address depends on the address family -- see above.)
None
is returned on success. On error, an
exception is raised, and there is no way to determine how much data,
if any, was successfully sent.
SO_*
etc.). The value can be an
integer or a string representing a buffer. In the latter case it is
up to the caller to ensure that the string contains the proper bits
(see the optional built-in module
struct for a way to encode C
structures as strings).
0
, further receives are disallowed. If how is 1
,
further sends are disallowed. If how is 2
, further sends
and receives are disallowed.
Note that there are no methods read() or write(); use recv() and send() without flags argument instead.
See About this document... for information on suggesting changes.