/socket.html
HTML | 1079 lines | 981 code | 98 blank | 0 comment | 0 complexity | 4c0d84cdabd49cf9f8982a3cf1d2c4ef MD5 | raw file
Possible License(s): GPL-3.0
Large files files are truncated, but you can click here to view the full file
- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
- <html><head><title>Python: module socket</title>
- </head><body bgcolor="#f0f0f8">
- <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading">
- <tr bgcolor="#7799ee">
- <td valign=bottom> <br>
- <font color="#ffffff" face="helvetica, arial"> <br><big><big><strong>socket</strong></big></big></font></td
- ><td align=right valign=bottom
- ><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/usr/lib/python2.7/socket.py">/usr/lib/python2.7/socket.py</a><br><a href="http://docs.python.org/library/socket">Module Docs</a></font></td></tr></table>
- <p><tt>This module provides <a href="#socket">socket</a> operations and some related functions.<br>
- On Unix, it supports IP (Internet Protocol) and Unix domain sockets.<br>
- On other systems, it only supports IP. Functions specific for a<br>
- <a href="#socket">socket</a> are available as methods of the <a href="#socket">socket</a> <a href="__builtin__.html#object">object</a>.<br>
- <br>
- Functions:<br>
- <br>
- <a href="#socket">socket</a>() -- create a new <a href="#socket">socket</a> <a href="__builtin__.html#object">object</a><br>
- <a href="#-socketpair">socketpair</a>() -- create a pair of new <a href="#socket">socket</a> objects [*]<br>
- <a href="#-fromfd">fromfd</a>() -- create a <a href="#socket">socket</a> <a href="__builtin__.html#object">object</a> from an open file descriptor [*]<br>
- <a href="#-gethostname">gethostname</a>() -- return the current hostname<br>
- <a href="#-gethostbyname">gethostbyname</a>() -- map a hostname to its IP number<br>
- <a href="#-gethostbyaddr">gethostbyaddr</a>() -- map an IP number or hostname to DNS info<br>
- <a href="#-getservbyname">getservbyname</a>() -- map a service name and a protocol name to a port number<br>
- <a href="#-getprotobyname">getprotobyname</a>() -- map a protocol name (e.g. 'tcp') to a number<br>
- <a href="#-ntohs">ntohs</a>(), <a href="#-ntohl">ntohl</a>() -- convert 16, 32 bit int from network to host byte order<br>
- <a href="#-htons">htons</a>(), <a href="#-htonl">htonl</a>() -- convert 16, 32 bit int from host to network byte order<br>
- <a href="#-inet_aton">inet_aton</a>() -- convert IP addr string (123.45.67.89) to 32-bit packed format<br>
- <a href="#-inet_ntoa">inet_ntoa</a>() -- convert 32-bit packed format IP to string (123.45.67.89)<br>
- ssl() -- secure <a href="#socket">socket</a> layer support (only available if configured)<br>
- <a href="#socket">socket</a>.<a href="#-getdefaulttimeout">getdefaulttimeout</a>() -- get the default <a href="#timeout">timeout</a> value<br>
- <a href="#socket">socket</a>.<a href="#-setdefaulttimeout">setdefaulttimeout</a>() -- set the default <a href="#timeout">timeout</a> value<br>
- <a href="#-create_connection">create_connection</a>() -- connects to an address, with an optional <a href="#timeout">timeout</a> and<br>
- optional source address.<br>
- <br>
- [*] not available on all platforms!<br>
- <br>
- Special objects:<br>
- <br>
- <a href="#SocketType">SocketType</a> -- type <a href="__builtin__.html#object">object</a> for <a href="#socket">socket</a> objects<br>
- <a href="#error">error</a> -- exception raised for I/O errors<br>
- has_ipv6 -- boolean value indicating if IPv6 is supported<br>
- <br>
- Integer constants:<br>
- <br>
- AF_INET, AF_UNIX -- <a href="#socket">socket</a> domains (first argument to <a href="#socket">socket</a>() call)<br>
- SOCK_STREAM, SOCK_DGRAM, SOCK_RAW -- <a href="#socket">socket</a> types (second argument)<br>
- <br>
- Many other constants may be defined; these may be used in calls to<br>
- the setsockopt() and getsockopt() methods.</tt></p>
- <p>
- <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
- <tr bgcolor="#aa55cc">
- <td colspan=3 valign=bottom> <br>
- <font color="#ffffff" face="helvetica, arial"><big><strong>Modules</strong></big></font></td></tr>
-
- <tr><td bgcolor="#aa55cc"><tt> </tt></td><td> </td>
- <td width="100%"><table width="100%" summary="list"><tr><td width="25%" valign=top><a href="_socket.html">_socket</a><br>
- <a href="_ssl.html">_ssl</a><br>
- </td><td width="25%" valign=top><a href="errno.html">errno</a><br>
- <a href="os.html">os</a><br>
- </td><td width="25%" valign=top><a href="sys.html">sys</a><br>
- <a href="warnings.html">warnings</a><br>
- </td><td width="25%" valign=top></td></tr></table></td></tr></table><p>
- <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
- <tr bgcolor="#ee77aa">
- <td colspan=3 valign=bottom> <br>
- <font color="#ffffff" face="helvetica, arial"><big><strong>Classes</strong></big></font></td></tr>
-
- <tr><td bgcolor="#ee77aa"><tt> </tt></td><td> </td>
- <td width="100%"><dl>
- <dt><font face="helvetica, arial"><a href="__builtin__.html#object">__builtin__.object</a>
- </font></dt><dd>
- <dl>
- <dt><font face="helvetica, arial"><a href="socket.html#_socketobject">_socketobject</a>
- </font></dt><dt><font face="helvetica, arial"><a href="socket.html#_socketobject">_socketobject</a>
- </font></dt></dl>
- </dd>
- <dt><font face="helvetica, arial"><a href="exceptions.html#IOError">exceptions.IOError</a>(<a href="exceptions.html#EnvironmentError">exceptions.EnvironmentError</a>)
- </font></dt><dd>
- <dl>
- <dt><font face="helvetica, arial"><a href="socket.html#error">error</a>
- </font></dt><dd>
- <dl>
- <dt><font face="helvetica, arial"><a href="socket.html#gaierror">gaierror</a>
- </font></dt><dt><font face="helvetica, arial"><a href="socket.html#herror">herror</a>
- </font></dt><dt><font face="helvetica, arial"><a href="socket.html#timeout">timeout</a>
- </font></dt></dl>
- </dd>
- </dl>
- </dd>
- </dl>
- <p>
- <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
- <tr bgcolor="#ffc8d8">
- <td colspan=3 valign=bottom> <br>
- <font color="#000000" face="helvetica, arial"><strong>SocketType</strong> = <a name="SocketType">class _socketobject</a>(<a href="__builtin__.html#object">__builtin__.object</a>)</font></td></tr>
-
- <tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td>
- <td colspan=2><tt><a href="#socket">socket</a>([family[, type[, proto]]]) -> <a href="#socket">socket</a> <a href="__builtin__.html#object">object</a><br>
- <br>
- Open a <a href="#socket">socket</a> of the given type. The family argument specifies the<br>
- address family; it defaults to AF_INET. The type argument specifies<br>
- whether this is a stream (SOCK_STREAM, this is the default)<br>
- or datagram (SOCK_DGRAM) <a href="#socket">socket</a>. The protocol argument defaults to 0,<br>
- specifying the default protocol. Keyword arguments are accepted.<br>
- <br>
- A <a href="#socket">socket</a> <a href="__builtin__.html#object">object</a> represents one endpoint of a network connection.<br>
- <br>
- Methods of <a href="#socket">socket</a> objects (keyword arguments not allowed):<br>
- <br>
- <a href="#SocketType-accept">accept</a>() -- accept a connection, returning new <a href="#socket">socket</a> and client address<br>
- <a href="#SocketType-bind">bind</a>(addr) -- bind the <a href="#socket">socket</a> to a local address<br>
- <a href="#SocketType-close">close</a>() -- close the <a href="#socket">socket</a><br>
- <a href="#SocketType-connect">connect</a>(addr) -- connect the <a href="#socket">socket</a> to a remote address<br>
- <a href="#SocketType-connect_ex">connect_ex</a>(addr) -- connect, return an <a href="#error">error</a> code instead of an exception<br>
- <a href="#SocketType-dup">dup</a>() -- return a new <a href="#socket">socket</a> <a href="__builtin__.html#object">object</a> identical to the current one [*]<br>
- <a href="#SocketType-fileno">fileno</a>() -- return underlying file descriptor<br>
- <a href="#SocketType-getpeername">getpeername</a>() -- return remote address [*]<br>
- <a href="#SocketType-getsockname">getsockname</a>() -- return local address<br>
- <a href="#SocketType-getsockopt">getsockopt</a>(level, optname[, buflen]) -- get <a href="#socket">socket</a> options<br>
- <a href="#SocketType-gettimeout">gettimeout</a>() -- return <a href="#timeout">timeout</a> or None<br>
- <a href="#SocketType-listen">listen</a>(n) -- start listening for incoming connections<br>
- <a href="#SocketType-makefile">makefile</a>([mode, [bufsize]]) -- return a file <a href="__builtin__.html#object">object</a> for the <a href="#socket">socket</a> [*]<br>
- <a href="#SocketType-recv">recv</a>(buflen[, flags]) -- receive data<br>
- <a href="#SocketType-recv_into">recv_into</a>(buffer[, nbytes[, flags]]) -- receive data (into a buffer)<br>
- <a href="#SocketType-recvfrom">recvfrom</a>(buflen[, flags]) -- receive data and sender's address<br>
- <a href="#SocketType-recvfrom_into">recvfrom_into</a>(buffer[, nbytes, [, flags])<br>
- -- receive data and sender's address (into a buffer)<br>
- <a href="#SocketType-sendall">sendall</a>(data[, flags]) -- send all data<br>
- <a href="#SocketType-send">send</a>(data[, flags]) -- send data, may not send all of it<br>
- <a href="#SocketType-sendto">sendto</a>(data[, flags], addr) -- send data to a given address<br>
- <a href="#SocketType-setblocking">setblocking</a>(0 | 1) -- set or clear the blocking I/O flag<br>
- <a href="#SocketType-setsockopt">setsockopt</a>(level, optname, value) -- set <a href="#socket">socket</a> options<br>
- <a href="#SocketType-settimeout">settimeout</a>(None | float) -- set or clear the <a href="#timeout">timeout</a><br>
- <a href="#SocketType-shutdown">shutdown</a>(how) -- shut down traffic in one or both directions<br>
- <br>
- [*] not available on all platforms!<br> </tt></td></tr>
- <tr><td> </td>
- <td width="100%">Methods defined here:<br>
- <dl><dt><a name="_socketobject-__init__"><strong>__init__</strong></a>(self, family<font color="#909090">=2</font>, type<font color="#909090">=1</font>, proto<font color="#909090">=0</font>, _sock<font color="#909090">=None</font>)</dt></dl>
- <dl><dt><a name="_socketobject-accept"><strong>accept</strong></a>(self)</dt><dd><tt><a href="#SocketType-accept">accept</a>() -> (<a href="#socket">socket</a> <a href="__builtin__.html#object">object</a>, address info)<br>
- <br>
- Wait for an incoming connection. Return a new <a href="#socket">socket</a> representing the<br>
- connection, and the address of the client. For IP sockets, the address<br>
- info is a pair (hostaddr, port).</tt></dd></dl>
- <dl><dt><a name="_socketobject-bind"><strong>bind</strong></a>(...)</dt><dd><tt><a href="#SocketType-bind">bind</a>(address)<br>
- <br>
- Bind the <a href="#socket">socket</a> to a local address. For IP sockets, the address is a<br>
- pair (host, port); the host must refer to the local host. For raw packet<br>
- sockets the address is a tuple (ifname, proto [,pkttype [,hatype]])</tt></dd></dl>
- <dl><dt><a name="_socketobject-close"><strong>close</strong></a>(self, _closedsocket<font color="#909090">=<class 'socket._closedsocket'></font>, _delegate_methods<font color="#909090">=('recv', 'recvfrom', 'recv_into', 'recvfrom_into', 'send', 'sendto')</font>, setattr<font color="#909090">=<built-in function setattr></font>)</dt><dd><tt><a href="#SocketType-close">close</a>()<br>
- <br>
- Close the <a href="#socket">socket</a>. It cannot be used after this call.</tt></dd></dl>
- <dl><dt><a name="_socketobject-connect"><strong>connect</strong></a>(...)</dt><dd><tt><a href="#SocketType-connect">connect</a>(address)<br>
- <br>
- Connect the <a href="#socket">socket</a> to a remote address. For IP sockets, the address<br>
- is a pair (host, port).</tt></dd></dl>
- <dl><dt><a name="_socketobject-connect_ex"><strong>connect_ex</strong></a>(...)</dt><dd><tt><a href="#SocketType-connect_ex">connect_ex</a>(address) -> errno<br>
- <br>
- This is like <a href="#SocketType-connect">connect</a>(address), but returns an <a href="#error">error</a> code (the errno value)<br>
- instead of raising an exception when an <a href="#error">error</a> occurs.</tt></dd></dl>
- <dl><dt><a name="_socketobject-dup"><strong>dup</strong></a>(self)</dt><dd><tt><a href="#SocketType-dup">dup</a>() -> <a href="#socket">socket</a> <a href="__builtin__.html#object">object</a><br>
- <br>
- Return a new <a href="#socket">socket</a> <a href="__builtin__.html#object">object</a> connected to the same system resource.</tt></dd></dl>
- <dl><dt><a name="_socketobject-fileno"><strong>fileno</strong></a>(...)</dt><dd><tt><a href="#SocketType-fileno">fileno</a>() -> integer<br>
- <br>
- Return the integer file descriptor of the <a href="#socket">socket</a>.</tt></dd></dl>
- <dl><dt><a name="_socketobject-getpeername"><strong>getpeername</strong></a>(...)</dt><dd><tt><a href="#SocketType-getpeername">getpeername</a>() -> address info<br>
- <br>
- Return the address of the remote endpoint. For IP sockets, the address<br>
- info is a pair (hostaddr, port).</tt></dd></dl>
- <dl><dt><a name="_socketobject-getsockname"><strong>getsockname</strong></a>(...)</dt><dd><tt><a href="#SocketType-getsockname">getsockname</a>() -> address info<br>
- <br>
- Return the address of the local endpoint. For IP sockets, the address<br>
- info is a pair (hostaddr, port).</tt></dd></dl>
- <dl><dt><a name="_socketobject-getsockopt"><strong>getsockopt</strong></a>(...)</dt><dd><tt><a href="#SocketType-getsockopt">getsockopt</a>(level, option[, buffersize]) -> value<br>
- <br>
- Get a <a href="#socket">socket</a> option. See the Unix manual for level and option.<br>
- If a nonzero buffersize argument is given, the return value is a<br>
- string of that length; otherwise it is an integer.</tt></dd></dl>
- <dl><dt><a name="_socketobject-gettimeout"><strong>gettimeout</strong></a>(...)</dt><dd><tt><a href="#SocketType-gettimeout">gettimeout</a>() -> <a href="#timeout">timeout</a><br>
- <br>
- Returns the <a href="#timeout">timeout</a> in seconds (float) associated with <a href="#socket">socket</a> <br>
- operations. A <a href="#timeout">timeout</a> of None indicates that timeouts on <a href="#socket">socket</a> <br>
- operations are disabled.</tt></dd></dl>
- <dl><dt><a name="_socketobject-listen"><strong>listen</strong></a>(...)</dt><dd><tt><a href="#SocketType-listen">listen</a>(backlog)<br>
- <br>
- Enable a server to accept connections. The backlog argument must be at<br>
- least 0 (if it is lower, it is set to 0); it specifies the number of<br>
- unaccepted connections that the system will allow before refusing new<br>
- connections.</tt></dd></dl>
- <dl><dt><a name="_socketobject-makefile"><strong>makefile</strong></a>(self, mode<font color="#909090">='r'</font>, bufsize<font color="#909090">=-1</font>)</dt><dd><tt><a href="#SocketType-makefile">makefile</a>([mode[, bufsize]]) -> file <a href="__builtin__.html#object">object</a><br>
- <br>
- Return a regular file <a href="__builtin__.html#object">object</a> corresponding to the <a href="#socket">socket</a>. The mode<br>
- and bufsize arguments are as for the built-in open() function.</tt></dd></dl>
- <dl><dt><a name="_socketobject-sendall"><strong>sendall</strong></a>(...)</dt><dd><tt><a href="#SocketType-sendall">sendall</a>(data[, flags])<br>
- <br>
- Send a data string to the <a href="#socket">socket</a>. For the optional flags<br>
- argument, see the Unix manual. This calls <a href="#SocketType-send">send</a>() repeatedly<br>
- until all data is sent. If an <a href="#error">error</a> occurs, it's impossible<br>
- to tell how much data has been sent.</tt></dd></dl>
- <dl><dt><a name="_socketobject-setblocking"><strong>setblocking</strong></a>(...)</dt><dd><tt><a href="#SocketType-setblocking">setblocking</a>(flag)<br>
- <br>
- Set the <a href="#socket">socket</a> to blocking (flag is true) or non-blocking (false).<br>
- <a href="#SocketType-setblocking">setblocking</a>(True) is equivalent to <a href="#SocketType-settimeout">settimeout</a>(None);<br>
- <a href="#SocketType-setblocking">setblocking</a>(False) is equivalent to <a href="#SocketType-settimeout">settimeout</a>(0.0).</tt></dd></dl>
- <dl><dt><a name="_socketobject-setsockopt"><strong>setsockopt</strong></a>(...)</dt><dd><tt><a href="#SocketType-setsockopt">setsockopt</a>(level, option, value)<br>
- <br>
- Set a <a href="#socket">socket</a> option. See the Unix manual for level and option.<br>
- The value argument can either be an integer or a string.</tt></dd></dl>
- <dl><dt><a name="_socketobject-settimeout"><strong>settimeout</strong></a>(...)</dt><dd><tt><a href="#SocketType-settimeout">settimeout</a>(<a href="#timeout">timeout</a>)<br>
- <br>
- Set a <a href="#timeout">timeout</a> on <a href="#socket">socket</a> operations. '<a href="#timeout">timeout</a>' can be a float,<br>
- giving in seconds, or None. Setting a <a href="#timeout">timeout</a> of None disables<br>
- the <a href="#timeout">timeout</a> feature and is equivalent to <a href="#SocketType-setblocking">setblocking</a>(1).<br>
- Setting a <a href="#timeout">timeout</a> of zero is the same as <a href="#SocketType-setblocking">setblocking</a>(0).</tt></dd></dl>
- <dl><dt><a name="_socketobject-shutdown"><strong>shutdown</strong></a>(...)</dt><dd><tt><a href="#SocketType-shutdown">shutdown</a>(flag)<br>
- <br>
- Shut down the reading side of the <a href="#socket">socket</a> (flag == SHUT_RD), the writing side<br>
- of the <a href="#socket">socket</a> (flag == SHUT_WR), or both ends (flag == SHUT_RDWR).</tt></dd></dl>
- <hr>
- Data descriptors defined here:<br>
- <dl><dt><strong>__weakref__</strong></dt>
- <dd><tt>list of weak references to the object (if defined)</tt></dd>
- </dl>
- <dl><dt><strong>family</strong></dt>
- <dd><tt>the socket family</tt></dd>
- </dl>
- <dl><dt><strong>proto</strong></dt>
- <dd><tt>the socket protocol</tt></dd>
- </dl>
- <dl><dt><strong>recv</strong></dt>
- </dl>
- <dl><dt><strong>recv_into</strong></dt>
- </dl>
- <dl><dt><strong>recvfrom</strong></dt>
- </dl>
- <dl><dt><strong>recvfrom_into</strong></dt>
- </dl>
- <dl><dt><strong>send</strong></dt>
- </dl>
- <dl><dt><strong>sendto</strong></dt>
- </dl>
- <dl><dt><strong>type</strong></dt>
- <dd><tt>the socket type</tt></dd>
- </dl>
- </td></tr></table> <p>
- <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
- <tr bgcolor="#ffc8d8">
- <td colspan=3 valign=bottom> <br>
- <font color="#000000" face="helvetica, arial"><a name="error">class <strong>error</strong></a>(<a href="exceptions.html#IOError">exceptions.IOError</a>)</font></td></tr>
-
- <tr><td bgcolor="#ffc8d8"><tt> </tt></td><td> </td>
- <td width="100%"><dl><dt>Method resolution order:</dt>
- <dd><a href="socket.html#error">error</a></dd>
- <dd><a href="exceptions.html#IOError">exceptions.IOError</a></dd>
- <dd><a href="exceptions.html#EnvironmentError">exceptions.EnvironmentError</a></dd>
- <dd><a href="exceptions.html#StandardError">exceptions.StandardError</a></dd>
- <dd><a href="exceptions.html#Exception">exceptions.Exception</a></dd>
- <dd><a href="exceptions.html#BaseException">exceptions.BaseException</a></dd>
- <dd><a href="__builtin__.html#object">__builtin__.object</a></dd>
- </dl>
- <hr>
- Data descriptors defined here:<br>
- <dl><dt><strong>__weakref__</strong></dt>
- <dd><tt>list of weak references to the object (if defined)</tt></dd>
- </dl>
- <hr>
- Methods inherited from <a href="exceptions.html#IOError">exceptions.IOError</a>:<br>
- <dl><dt><a name="error-__init__"><strong>__init__</strong></a>(...)</dt><dd><tt>x.<a href="#error-__init__">__init__</a>(...) initializes x; see help(type(x)) for signature</tt></dd></dl>
- <hr>
- Data and other attributes inherited from <a href="exceptions.html#IOError">exceptions.IOError</a>:<br>
- <dl><dt><strong>__new__</strong> = <built-in method __new__ of type object><dd><tt>T.<a href="#error-__new__">__new__</a>(S, ...) -> a new <a href="__builtin__.html#object">object</a> with type S, a subtype of T</tt></dl>
- <hr>
- Methods inherited from <a href="exceptions.html#EnvironmentError">exceptions.EnvironmentError</a>:<br>
- <dl><dt><a name="error-__reduce__"><strong>__reduce__</strong></a>(...)</dt></dl>
- <dl><dt><a name="error-__str__"><strong>__str__</strong></a>(...)</dt><dd><tt>x.<a href="#error-__str__">__str__</a>() <==> str(x)</tt></dd></dl>
- <hr>
- Data descriptors inherited from <a href="exceptions.html#EnvironmentError">exceptions.EnvironmentError</a>:<br>
- <dl><dt><strong>errno</strong></dt>
- <dd><tt>exception errno</tt></dd>
- </dl>
- <dl><dt><strong>filename</strong></dt>
- <dd><tt>exception filename</tt></dd>
- </dl>
- <dl><dt><strong>strerror</strong></dt>
- <dd><tt>exception strerror</tt></dd>
- </dl>
- <hr>
- Methods inherited from <a href="exceptions.html#BaseException">exceptions.BaseException</a>:<br>
- <dl><dt><a name="error-__delattr__"><strong>__delattr__</strong></a>(...)</dt><dd><tt>x.<a href="#error-__delattr__">__delattr__</a>('name') <==> del x.name</tt></dd></dl>
- <dl><dt><a name="error-__getattribute__"><strong>__getattribute__</strong></a>(...)</dt><dd><tt>x.<a href="#error-__getattribute__">__getattribute__</a>('name') <==> x.name</tt></dd></dl>
- <dl><dt><a name="error-__getitem__"><strong>__getitem__</strong></a>(...)</dt><dd><tt>x.<a href="#error-__getitem__">__getitem__</a>(y) <==> x[y]</tt></dd></dl>
- <dl><dt><a name="error-__getslice__"><strong>__getslice__</strong></a>(...)</dt><dd><tt>x.<a href="#error-__getslice__">__getslice__</a>(i, j) <==> x[i:j]<br>
- <br>
- Use of negative indices is not supported.</tt></dd></dl>
- <dl><dt><a name="error-__repr__"><strong>__repr__</strong></a>(...)</dt><dd><tt>x.<a href="#error-__repr__">__repr__</a>() <==> repr(x)</tt></dd></dl>
- <dl><dt><a name="error-__setattr__"><strong>__setattr__</strong></a>(...)</dt><dd><tt>x.<a href="#error-__setattr__">__setattr__</a>('name', value) <==> x.name = value</tt></dd></dl>
- <dl><dt><a name="error-__setstate__"><strong>__setstate__</strong></a>(...)</dt></dl>
- <dl><dt><a name="error-__unicode__"><strong>__unicode__</strong></a>(...)</dt></dl>
- <hr>
- Data descriptors inherited from <a href="exceptions.html#BaseException">exceptions.BaseException</a>:<br>
- <dl><dt><strong>__dict__</strong></dt>
- </dl>
- <dl><dt><strong>args</strong></dt>
- </dl>
- <dl><dt><strong>message</strong></dt>
- </dl>
- </td></tr></table> <p>
- <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
- <tr bgcolor="#ffc8d8">
- <td colspan=3 valign=bottom> <br>
- <font color="#000000" face="helvetica, arial"><a name="gaierror">class <strong>gaierror</strong></a>(<a href="socket.html#error">error</a>)</font></td></tr>
-
- <tr><td bgcolor="#ffc8d8"><tt> </tt></td><td> </td>
- <td width="100%"><dl><dt>Method resolution order:</dt>
- <dd><a href="socket.html#gaierror">gaierror</a></dd>
- <dd><a href="socket.html#error">error</a></dd>
- <dd><a href="exceptions.html#IOError">exceptions.IOError</a></dd>
- <dd><a href="exceptions.html#EnvironmentError">exceptions.EnvironmentError</a></dd>
- <dd><a href="exceptions.html#StandardError">exceptions.StandardError</a></dd>
- <dd><a href="exceptions.html#Exception">exceptions.Exception</a></dd>
- <dd><a href="exceptions.html#BaseException">exceptions.BaseException</a></dd>
- <dd><a href="__builtin__.html#object">__builtin__.object</a></dd>
- </dl>
- <hr>
- Data descriptors inherited from <a href="socket.html#error">error</a>:<br>
- <dl><dt><strong>__weakref__</strong></dt>
- <dd><tt>list of weak references to the object (if defined)</tt></dd>
- </dl>
- <hr>
- Methods inherited from <a href="exceptions.html#IOError">exceptions.IOError</a>:<br>
- <dl><dt><a name="gaierror-__init__"><strong>__init__</strong></a>(...)</dt><dd><tt>x.<a href="#gaierror-__init__">__init__</a>(...) initializes x; see help(type(x)) for signature</tt></dd></dl>
- <hr>
- Data and other attributes inherited from <a href="exceptions.html#IOError">exceptions.IOError</a>:<br>
- <dl><dt><strong>__new__</strong> = <built-in method __new__ of type object><dd><tt>T.<a href="#gaierror-__new__">__new__</a>(S, ...) -> a new <a href="__builtin__.html#object">object</a> with type S, a subtype of T</tt></dl>
- <hr>
- Methods inherited from <a href="exceptions.html#EnvironmentError">exceptions.EnvironmentError</a>:<br>
- <dl><dt><a name="gaierror-__reduce__"><strong>__reduce__</strong></a>(...)</dt></dl>
- <dl><dt><a name="gaierror-__str__"><strong>__str__</strong></a>(...)</dt><dd><tt>x.<a href="#gaierror-__str__">__str__</a>() <==> str(x)</tt></dd></dl>
- <hr>
- Data descriptors inherited from <a href="exceptions.html#EnvironmentError">exceptions.EnvironmentError</a>:<br>
- <dl><dt><strong>errno</strong></dt>
- <dd><tt>exception errno</tt></dd>
- </dl>
- <dl><dt><strong>filename</strong></dt>
- <dd><tt>exception filename</tt></dd>
- </dl>
- <dl><dt><strong>strerror</strong></dt>
- <dd><tt>exception strerror</tt></dd>
- </dl>
- <hr>
- Methods inherited from <a href="exceptions.html#BaseException">exceptions.BaseException</a>:<br>
- <dl><dt><a name="gaierror-__delattr__"><strong>__delattr__</strong></a>(...)</dt><dd><tt>x.<a href="#gaierror-__delattr__">__delattr__</a>('name') <==> del x.name</tt></dd></dl>
- <dl><dt><a name="gaierror-__getattribute__"><strong>__getattribute__</strong></a>(...)</dt><dd><tt>x.<a href="#gaierror-__getattribute__">__getattribute__</a>('name') <==> x.name</tt></dd></dl>
- <dl><dt><a name="gaierror-__getitem__"><strong>__getitem__</strong></a>(...)</dt><dd><tt>x.<a href="#gaierror-__getitem__">__getitem__</a>(y) <==> x[y]</tt></dd></dl>
- <dl><dt><a name="gaierror-__getslice__"><strong>__getslice__</strong></a>(...)</dt><dd><tt>x.<a href="#gaierror-__getslice__">__getslice__</a>(i, j) <==> x[i:j]<br>
- <br>
- Use of negative indices is not supported.</tt></dd></dl>
- <dl><dt><a name="gaierror-__repr__"><strong>__repr__</strong></a>(...)</dt><dd><tt>x.<a href="#gaierror-__repr__">__repr__</a>() <==> repr(x)</tt></dd></dl>
- <dl><dt><a name="gaierror-__setattr__"><strong>__setattr__</strong></a>(...)</dt><dd><tt>x.<a href="#gaierror-__setattr__">__setattr__</a>('name', value) <==> x.name = value</tt></dd></dl>
- <dl><dt><a name="gaierror-__setstate__"><strong>__setstate__</strong></a>(...)</dt></dl>
- <dl><dt><a name="gaierror-__unicode__"><strong>__unicode__</strong></a>(...)</dt></dl>
- <hr>
- Data descriptors inherited from <a href="exceptions.html#BaseException">exceptions.BaseException</a>:<br>
- <dl><dt><strong>__dict__</strong></dt>
- </dl>
- <dl><dt><strong>args</strong></dt>
- </dl>
- <dl><dt><strong>message</strong></dt>
- </dl>
- </td></tr></table> <p>
- <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
- <tr bgcolor="#ffc8d8">
- <td colspan=3 valign=bottom> <br>
- <font color="#000000" face="helvetica, arial"><a name="herror">class <strong>herror</strong></a>(<a href="socket.html#error">error</a>)</font></td></tr>
-
- <tr><td bgcolor="#ffc8d8"><tt> </tt></td><td> </td>
- <td width="100%"><dl><dt>Method resolution order:</dt>
- <dd><a href="socket.html#herror">herror</a></dd>
- <dd><a href="socket.html#error">error</a></dd>
- <dd><a href="exceptions.html#IOError">exceptions.IOError</a></dd>
- <dd><a href="exceptions.html#EnvironmentError">exceptions.EnvironmentError</a></dd>
- <dd><a href="exceptions.html#StandardError">exceptions.StandardError</a></dd>
- <dd><a href="exceptions.html#Exception">exceptions.Exception</a></dd>
- <dd><a href="exceptions.html#BaseException">exceptions.BaseException</a></dd>
- <dd><a href="__builtin__.html#object">__builtin__.object</a></dd>
- </dl>
- <hr>
- Data descriptors inherited from <a href="socket.html#error">error</a>:<br>
- <dl><dt><strong>__weakref__</strong></dt>
- <dd><tt>list of weak references to the object (if defined)</tt></dd>
- </dl>
- <hr>
- Methods inherited from <a href="exceptions.html#IOError">exceptions.IOError</a>:<br>
- <dl><dt><a name="herror-__init__"><strong>__init__</strong></a>(...)</dt><dd><tt>x.<a href="#herror-__init__">__init__</a>(...) initializes x; see help(type(x)) for signature</tt></dd></dl>
- <hr>
- Data and other attributes inherited from <a href="exceptions.html#IOError">exceptions.IOError</a>:<br>
- <dl><dt><strong>__new__</strong> = <built-in method __new__ of type object><dd><tt>T.<a href="#herror-__new__">__new__</a>(S, ...) -> a new <a href="__builtin__.html#object">object</a> with type S, a subtype of T</tt></dl>
- <hr>
- Methods inherited from <a href="exceptions.html#EnvironmentError">exceptions.EnvironmentError</a>:<br>
- <dl><dt><a name="herror-__reduce__"><strong>__reduce__</strong></a>(...)</dt></dl>
- <dl><dt><a name="herror-__str__"><strong>__str__</strong></a>(...)</dt><dd><tt>x.<a href="#herror-__str__">__str__</a>() <==> str(x)</tt></dd></dl>
- <hr>
- Data descriptors inherited from <a href="exceptions.html#EnvironmentError">exceptions.EnvironmentError</a>:<br>
- <dl><dt><strong>errno</strong></dt>
- <dd><tt>exception errno</tt></dd>
- </dl>
- <dl><dt><strong>filename</strong></dt>
- <dd><tt>exception filename</tt></dd>
- </dl>
- <dl><dt><strong>strerror</strong></dt>
- <dd><tt>exception strerror</tt></dd>
- </dl>
- <hr>
- Methods inherited from <a href="exceptions.html#BaseException">exceptions.BaseException</a>:<br>
- <dl><dt><a name="herror-__delattr__"><strong>__delattr__</strong></a>(...)</dt><dd><tt>x.<a href="#herror-__delattr__">__delattr__</a>('name') <==> del x.name</tt></dd></dl>
- <dl><dt><a name="herror-__getattribute__"><strong>__getattribute__</strong></a>(...)</dt><dd><tt>x.<a href="#herror-__getattribute__">__getattribute__</a>('name') <==> x.name</tt></dd></dl>
- <dl><dt><a name="herror-__getitem__"><strong>__getitem__</strong></a>(...)</dt><dd><tt>x.<a href="#herror-__getitem__">__getitem__</a>(y) <==> x[y]</tt></dd></dl>
- <dl><dt><a name="herror-__getslice__"><strong>__getslice__</strong></a>(...)</dt><dd><tt>x.<a href="#herror-__getslice__">__getslice__</a>(i, j) <==> x[i:j]<br>
- <br>
- Use of negative indices is not supported.</tt></dd></dl>
- <dl><dt><a name="herror-__repr__"><strong>__repr__</strong></a>(...)</dt><dd><tt>x.<a href="#herror-__repr__">__repr__</a>() <==> repr(x)</tt></dd></dl>
- <dl><dt><a name="herror-__setattr__"><strong>__setattr__</strong></a>(...)</dt><dd><tt>x.<a href="#herror-__setattr__">__setattr__</a>('name', value) <==> x.name = value</tt></dd></dl>
- <dl><dt><a name="herror-__setstate__"><strong>__setstate__</strong></a>(...)</dt></dl>
- <dl><dt><a name="herror-__unicode__"><strong>__unicode__</strong></a>(...)</dt></dl>
- <hr>
- Data descriptors inherited from <a href="exceptions.html#BaseException">exceptions.BaseException</a>:<br>
- <dl><dt><strong>__dict__</strong></dt>
- </dl>
- <dl><dt><strong>args</strong></dt>
- </dl>
- <dl><dt><strong>message</strong></dt>
- </dl>
- </td></tr></table> <p>
- <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
- <tr bgcolor="#ffc8d8">
- <td colspan=3 valign=bottom> <br>
- <font color="#000000" face="helvetica, arial"><strong>socket</strong> = <a name="socket">class _socketobject</a>(<a href="__builtin__.html#object">__builtin__.object</a>)</font></td></tr>
-
- <tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td>
- <td colspan=2><tt><a href="#socket">socket</a>([family[, type[, proto]]]) -> <a href="#socket">socket</a> <a href="__builtin__.html#object">object</a><br>
- <br>
- Open a <a href="#socket">socket</a> of the given type. The family argument specifies the<br>
- address family; it defaults to AF_INET. The type argument specifies<br>
- whether this is a stream (SOCK_STREAM, this is the default)<br>
- or datagram (SOCK_DGRAM) <a href="#socket">socket</a>. The protocol argument defaults to 0,<br>
- specifying the default protocol. Keyword arguments are accepted.<br>
- <br>
- A <a href="#socket">socket</a> <a href="__builtin__.html#object">object</a> represents one endpoint of a network connection.<br>
- <br>
- Methods of <a href="#socket">socket</a> objects (keyword arguments not allowed):<br>
- <br>
- <a href="#socket-accept">accept</a>() -- accept a connection, returning new <a href="#socket">socket</a> and client address<br>
- <a href="#socket-bind">bind</a>(addr) -- bind the <a href="#socket">socket</a> to a local address<br>
- <a href="#socket-close">close</a>() -- close the <a href="#socket">socket</a><br>
- <a href="#socket-connect">connect</a>(addr) -- connect the <a href="#socket">socket</a> to a remote address<br>
- <a href="#socket-connect_ex">connect_ex</a>(addr) -- connect, return an <a href="#error">error</a> code instead of an exception<br>
- <a href="#socket-dup">dup</a>() -- return a new <a href="#socket">socket</a> <a href="__builtin__.html#object">object</a> identical to the current one [*]<br>
- <a href="#socket-fileno">fileno</a>() -- return underlying file descriptor<br>
- <a href="#socket-getpeername">getpeername</a>() -- return remote address [*]<br>
- <a href="#socket-getsockname">getsockname</a>() -- return local address<br>
- <a href="#socket-getsockopt">getsockopt</a>(level, optname[, buflen]) -- get <a href="#socket">socket</a> options<br>
- <a href="#socket-gettimeout">gettimeout</a>() -- return <a href="#timeout">timeout</a> or None<br>
- <a href="#socket-listen">listen</a>(n) -- start listening for incoming connections<br>
- <a href="#socket-makefile">makefile</a>([mode, [bufsize]]) -- return a file <a href="__builtin__.html#object">object</a> for the <a href="#socket">socket</a> [*]<br>
- <a href="#socket-recv">recv</a>(buflen[, flags]) -- receive data<br>
- <a href="#socket-recv_into">recv_into</a>(buffer[, nbytes[, flags]]) -- receive data (into a buffer)<br>
- <a href="#socket-recvfrom">recvfrom</a>(buflen[, flags]) -- receive data and sender's address<br>
- <a href="#socket-recvfrom_into">recvfrom_into</a>(buffer[, nbytes, [, flags])<br>
- -- receive data and sender's address (into a buffer)<br>
- <a href="#socket-sendall">sendall</a>(data[, flags]) -- send all data<br>
- <a href="#socket-send">send</a>(data[, flags]) -- send data, may not send all of it<br>
- <a href="#socket-sendto">sendto</a>(data[, flags], addr) -- send data to a given address<br>
- <a href="#socket-setblocking">setblocking</a>(0 | 1) -- set or clear the blocking I/O flag<br>
- <a href="#socket-setsockopt">setsockopt</a>(level, optname, value) -- set <a href="#socket">socket</a> options<br>
- <a href="#socket-settimeout">settimeout</a>(None | float) -- set or clear the <a href="#timeout">timeout</a><br>
- <a href="#socket-shutdown">shutdown</a>(how) -- shut down traffic in one or both directions<br>
- <br>
- [*] not available on all platforms!<br> </tt></td></tr>
- <tr><td> </td>
- <td width="100%">Methods defined here:<br>
- <dl><dt><a name="_socketobject-__init__"><strong>__init__</strong></a>(self, family<font color="#909090">=2</font>, type<font color="#909090">=1</font>, proto<font color="#909090">=0</font>, _sock<font color="#909090">=None</font>)</dt></dl>
- <dl><dt><a name="_socketobject-accept"><strong>accept</strong></a>(self)</dt><dd><tt><a href="#socket-accept">accept</a>() -> (<a href="#socket">socket</a> <a href="__builtin__.html#object">object</a>, address info)<br>
- <br>
- Wait for an incoming connection. Return a new <a href="#socket">socket</a> representing the<br>
- connection, and the address of the client. For IP sockets, the address<br>
- info is a pair (hostaddr, port).</tt></dd></dl>
- <dl><dt><a name="_socketobject-bind"><strong>bind</strong></a>(...)</dt><dd><tt><a href="#socket-bind">bind</a>(address)<br>
- <br>
- Bind the <a href="#socket">socket</a> to a local address. For IP sockets, the address is a<br>
- pair (host, port); the host must refer to the local host. For raw packet<br>
- sockets the address is a tuple (ifname, proto [,pkttype [,hatype]])</tt></dd></dl>
- <dl><dt><a name="_socketobject-close"><strong>close</strong></a>(self, _closedsocket<font color="#909090">=<class 'socket._closedsocket'></font>, _delegate_methods<font color="#909090">=('recv', 'recvfrom', 'recv_into', 'recvfrom_into', 'send', 'sendto')</font>, setattr<font color="#909090">=<built-in function setattr></font>)</dt><dd><tt><a href="#socket-close">close</a>()<br>
- <br>
- Close the <a href="#socket">socket</a>. It cannot be used after this call.</tt></dd></dl>
- <dl><dt><a name="_socketobject-connect"><strong>connect</strong></a>(...)</dt><dd><tt><a href="#socket-connect">connect</a>(address)<br>
- <br>
- Connect the <a href="#socket">socket</a> to a remote address. For IP sockets, the address<br>
- is a pair (host, port).</tt></dd></dl>
- <dl><dt><a name="_socketobject-connect_ex"><strong>connect_ex</strong></a>(...)</dt><dd><tt><a href="#socket-connect_ex">connect_ex</a>(address) -> errno<br>
- <br>
- This is like <a href="#socket-connect">connect</a>(address), but returns an <a href="#error">error</a> code (the errno value)<br>
- instead of raising an exception when an <a href="#error">error</a> occurs.</tt></dd></dl>
- <dl><dt><a name="_socketobject-dup"><strong>dup</strong></a>(self)</dt><dd><tt><a href="#socket-dup">dup</a>() -> <a href="#socket">socket</a> <a href="__builtin__.html#object">object</a><br>
- <br>
- Return a new <a href="#socket">socket</a> <a href="__builtin__.html#object">object</a> connected to the same system resource.</tt></dd></dl>
- <dl><dt><a name="_socketobject-fileno"><strong>fileno</strong></a>(...)</dt><dd><tt><a href="#socket-fileno">fileno</a>() -> integer<br>
- <br>
- Return the integer file descriptor of the <a href="#socket">socket</a>.</tt></dd></dl>
- <dl><dt><a name="_socketobject-getpeername"><strong>getpeername</strong></a>(...)</dt><dd><tt><a href="#socket-getpeername">getpeername</a>() -> address info<br>
- <br>
- Return the address of the remote endpoint. For IP sockets, the address<br>
- info is a pair (hostaddr, port).</tt></dd></dl>
- <dl><dt><a name="_socketobject-getsockname"><strong>getsockname</strong></a>(...)</dt><dd><tt><a href="#socket-getsockname">getsockname</a>() -> address info<br>
- <br>
- Return the address of the local endpoint. For IP sockets, the address<br>
- info is a pair (hostaddr, port).</tt></dd></dl>
- <dl><dt><a name="_socketobject-getsockopt"><strong>getsockopt</strong></a>(...)</dt><dd><tt><a href="#socket-getsockopt">getsockopt</a>(level, option[, buffersize]) -> value<br>
- <br>
- Get a <a href="#socket">socket</a> option. See the Unix manual for level and option.<br>
- If a nonzero buffersize argument is given, the return value is a<br>
- string of that length; otherwise it is an integer.</tt></dd></dl>
- <dl><dt><a name="_socketobject-gettimeout"><strong>gettimeout</strong></a>(...)</dt><dd><tt><a href="#socket-gettimeout">gettimeout</a>() -> <a href="#timeout">timeout</a><br>
- <br>
- Returns the <a href="#timeout">timeout</a> in seconds (float) associated with <a href="#socket">socket</a> <br>
- operations. A <a href="#timeout">timeout</a> of None indicates that timeouts on <a href="#socket">socket</a> <br>
- operations are disabled.</tt></dd></dl>
- <dl><dt><a name="_socketobject-listen"><strong>listen</strong></a>(...)</dt><dd><tt><a href="#socket-listen">listen</a>(backlog)<br>
- <br>
- Enable a server to accept connections. The backlog argument must be at<br>
- least 0 (if it is lower, it is set to 0); it specifies the number of<br>
- unaccepted connections that the system will allow before refusing new<br>
- connections.</tt></dd></dl>
- <dl><dt><a name="_socketobject-makefile"><strong>makefile</strong></a>(self, mode<font color="#909090">='r'</font>, bufsize<font color="#909090">=-1</font>)</dt><dd><tt><a href="#socket-makefile">makefile</a>([mode[, bufsize]]) -> file <a href="__builtin__.html#object">object</a><br>
- <br>
- Return a regular file <a href="__builtin__.html#object">object</a> corresponding to the <a href="#socket">socket</a>. The mode<br>
- and bufsize arguments are as for the built-in open() function.</tt></dd></dl>
- <dl><dt><a name="_socketobject-sendall"><strong>sendall</strong></a>(...)</dt><dd><tt><a href="#socket-sendall">sendall</a>(data[, flags])<br>
- <br>
- Send a data string to the <a href="#socket">socket</a>. For the optional flags<br>
- argument, see the Unix manual. This calls <a href="#socket-send">send</a>() repeatedly<br>
- until all data is sent. If an <a href="#error">error</a> occurs, it's impossible<br>
- to tell how much data has been sent.</tt></dd></dl>
- <dl><dt><a name="_socketobject-setblocking"><strong>setblocking</strong></a>(...)</dt><dd><tt><a href="#socket-setblocking">setblocking</a>(flag)<br>
- <br>
- Set the <a href="#socket">socket</a> to blocking (flag is true) or non-blocking (false).<br>
- <a href="#socket-setblocking">setblocking</a>(True) is equivalent to <a href="#socket-settimeout">settimeout</a>(None);<br>
- <a href="#socket-setblocking">setblocking</a>(False) is equivalent to <a href="#socket-settimeout">settimeout</a>(0.0).</tt></dd></dl>
- <dl><dt><a name="_socketobject-setsockopt"><strong>setsockopt</strong></a>(...)</dt><dd><tt><a href="#socket-setsockopt">setsockopt</a>(level, option, value)<br>
- <br>
- Set a <a href="#socket">socket</a> option. See the Unix manual for level and option.<br>
- The value argument can either be an integer or a string.</tt></dd></dl>
- <dl><dt><a name="_socketobject-settimeout"><strong>settimeout</strong></a>(...)</dt><dd><tt><a href="#socket-settimeout">settimeout</a>(<a href="#timeout">timeout</a>)<br>
- <br>
- Set a …
Large files files are truncated, but you can click here to view the full file