Mercurial > cpython-lru_cache-weakref
annotate Doc/lib/libsocket.tex @ 37372:42312e5f11fd 2.4
Bug #1460564: document that socket.fromfd() duplicates the given
file descriptor.
(backport from rev. 43523)
| author | Georg Brandl <georg@python.org> |
|---|---|
| date | Sat, 01 Apr 2006 07:33:22 +0000 |
| parents | 76d511972616 |
| children | 3473fcf0bcee |
| rev | line source |
|---|---|
| 8918 | 1 \section{\module{socket} --- |
| 10655 | 2 Low-level networking interface} |
| 3 | |
|
8716
760dcf197048
Adjusted to use the new module synopsis support macros.
Fred Drake <fdrake@acm.org>
parents:
7877
diff
changeset
|
4 \declaremodule{builtin}{socket} |
|
760dcf197048
Adjusted to use the new module synopsis support macros.
Fred Drake <fdrake@acm.org>
parents:
7877
diff
changeset
|
5 \modulesynopsis{Low-level networking interface.} |
|
760dcf197048
Adjusted to use the new module synopsis support macros.
Fred Drake <fdrake@acm.org>
parents:
7877
diff
changeset
|
6 |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
7 |
|
7096
5bb884527446
Consistency: "{\bf ...}" ==> "\strong{...}"
Fred Drake <fdrake@acm.org>
parents:
6804
diff
changeset
|
8 This module provides access to the BSD \emph{socket} interface. |
|
12223
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
9 It is available on all modern \UNIX{} systems, Windows, MacOS, BeOS, |
|
35672
412d21e30c13
Backport: SF Bug #1308042, platform dependent behaviour (Windoze of course) in UDP sockets.
Neal Norwitz <nnorwitz@gmail.com>
parents:
34739
diff
changeset
|
10 OS/2, and probably additional platforms. \note{Some behavior may be |
|
412d21e30c13
Backport: SF Bug #1308042, platform dependent behaviour (Windoze of course) in UDP sockets.
Neal Norwitz <nnorwitz@gmail.com>
parents:
34739
diff
changeset
|
11 platform dependent, since calls are made to the operating system socket APIs.} |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
12 |
|
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
13 For an introduction to socket programming (in C), see the following |
|
11463
17e12305973e
Use \citetitle and \programopt as appropriate.
Fred Drake <fdrake@acm.org>
parents:
11291
diff
changeset
|
14 papers: \citetitle{An Introductory 4.3BSD Interprocess Communication |
|
17e12305973e
Use \citetitle and \programopt as appropriate.
Fred Drake <fdrake@acm.org>
parents:
11291
diff
changeset
|
15 Tutorial}, by Stuart Sechrest and \citetitle{An Advanced 4.3BSD |
|
17e12305973e
Use \citetitle and \programopt as appropriate.
Fred Drake <fdrake@acm.org>
parents:
11291
diff
changeset
|
16 Interprocess Communication Tutorial}, by Samuel J. Leffler et al, |
|
17e12305973e
Use \citetitle and \programopt as appropriate.
Fred Drake <fdrake@acm.org>
parents:
11291
diff
changeset
|
17 both in the \citetitle{\UNIX{} Programmer's Manual, Supplementary Documents 1} |
|
12223
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
18 (sections PS1:7 and PS1:8). The platform-specific reference material |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
19 for the various socket-related system calls are also a valuable source |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
20 of information on the details of socket semantics. For \UNIX, refer |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
21 to the manual pages; for Windows, see the WinSock (or Winsock 2) |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
22 specification. |
| 20127 | 23 For IPv6-ready APIs, readers may want to refer to \rfc{2553} titled |
| 24 \citetitle{Basic Socket Interface Extensions for IPv6}. | |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
25 |
|
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
26 The Python interface is a straightforward transliteration of the |
|
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
27 \UNIX{} system call and library interface for sockets to Python's |
| 7632 | 28 object-oriented style: the \function{socket()} function returns a |
| 10655 | 29 \dfn{socket object}\obindex{socket} whose methods implement the |
| 30 various socket system calls. Parameter types are somewhat | |
| 31 higher-level than in the C interface: as with \method{read()} and | |
| 32 \method{write()} operations on Python files, buffer allocation on | |
| 33 receive operations is automatic, and buffer length is implicit on send | |
| 34 operations. | |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
35 |
|
18995
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
36 Socket addresses are represented as follows: |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
37 A single string is used for the \constant{AF_UNIX} address family. |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
38 A pair \code{(\var{host}, \var{port})} is used for the |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
39 \constant{AF_INET} address family, where \var{host} is a string |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
40 representing either a hostname in Internet domain notation like |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
41 \code{'daring.cwi.nl'} or an IPv4 address like \code{'100.50.200.5'}, |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
42 and \var{port} is an integral port number. |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
43 For \constant{AF_INET6} address family, a four-tuple |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
44 \code{(\var{host}, \var{port}, \var{flowinfo}, \var{scopeid})} is |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
45 used, where \var{flowinfo} and \var{scopeid} represents |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
46 \code{sin6_flowinfo} and \code{sin6_scope_id} member in |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
47 \constant{struct sockaddr_in6} in C. |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
48 For \module{socket} module methods, \var{flowinfo} and \var{scopeid} |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
49 can be omitted just for backward compatibility. Note, however, |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
50 omission of \var{scopeid} can cause problems in manipulating scoped |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
51 IPv6 addresses. Other address families are currently not supported. |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
52 The address format required by a particular socket object is |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
53 automatically selected based on the address family specified when the |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
54 socket object was created. |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
55 |
|
18995
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
56 For IPv4 addresses, two special forms are accepted instead of a host |
| 7632 | 57 address: the empty string represents \constant{INADDR_ANY}, and the string |
| 10655 | 58 \code{'<broadcast>'} represents \constant{INADDR_BROADCAST}. |
|
18995
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
59 The behavior is not available for IPv6 for backward compatibility, |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
60 therefore, you may want to avoid these if you intend to support IPv6 with |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
61 your Python programs. |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
62 |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
63 If you use a hostname in the \var{host} portion of IPv4/v6 socket |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
64 address, the program may show a nondeterministic behavior, as Python |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
65 uses the first address returned from the DNS resolution. The socket |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
66 address will be resolved differently into an actual IPv4/v6 address, |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
67 depending on the results from DNS resolution and/or the host |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
68 configuration. For deterministic behavior use a numeric address in |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
69 \var{host} portion. |
|
5461
0ded63bcf5de
Document "" and "<broadcast>".
Guido van Rossum <guido@python.org>
parents:
4929
diff
changeset
|
70 |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
71 All errors raise exceptions. The normal exceptions for invalid |
|
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
72 argument types and out-of-memory conditions can be raised; errors |
| 10655 | 73 related to socket or address semantics raise the error |
| 74 \exception{socket.error}. | |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
75 |
|
23815
203d1412a7e8
Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents:
23730
diff
changeset
|
76 Non-blocking mode is supported through |
|
203d1412a7e8
Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents:
23730
diff
changeset
|
77 \method{setblocking()}. A generalization of this based on timeouts |
|
203d1412a7e8
Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents:
23730
diff
changeset
|
78 is supported through \method{settimeout()}. |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
79 |
| 7632 | 80 The module \module{socket} exports the following constants and functions: |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
81 |
| 7632 | 82 |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
83 \begin{excdesc}{error} |
|
18995
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
84 This exception is raised for socket-related errors. |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
85 The accompanying value is either a string telling what went wrong or a |
|
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
86 pair \code{(\var{errno}, \var{string})} |
|
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
87 representing an error returned by a system |
| 10655 | 88 call, similar to the value accompanying \exception{os.error}. |
| 89 See the module \refmodule{errno}\refbimodindex{errno}, which contains | |
|
7200
98a9da520f1d
Add ref to errno module, and change ref to posix.error to os.error.
Guido van Rossum <guido@python.org>
parents:
7135
diff
changeset
|
90 names for the error codes defined by the underlying operating system. |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
91 \end{excdesc} |
|
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
92 |
|
18995
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
93 \begin{excdesc}{herror} |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
94 This exception is raised for address-related errors, i.e. for |
|
21521
e0a5d16a9cb9
Add notes that fromfd() and s.makefile() are Unix-specific.
Fred Drake <fdrake@acm.org>
parents:
21213
diff
changeset
|
95 functions that use \var{h_errno} in the C API, including |
|
e0a5d16a9cb9
Add notes that fromfd() and s.makefile() are Unix-specific.
Fred Drake <fdrake@acm.org>
parents:
21213
diff
changeset
|
96 \function{gethostbyname_ex()} and \function{gethostbyaddr()}. |
|
18995
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
97 |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
98 The accompanying value is a pair \code{(\var{h_errno}, \var{string})} |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
99 representing an error returned by a library call. \var{string} |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
100 represents the description of \var{h_errno}, as returned by |
|
21521
e0a5d16a9cb9
Add notes that fromfd() and s.makefile() are Unix-specific.
Fred Drake <fdrake@acm.org>
parents:
21213
diff
changeset
|
101 the \cfunction{hstrerror()} C function. |
|
18995
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
102 \end{excdesc} |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
103 |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
104 \begin{excdesc}{gaierror} |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
105 This exception is raised for address-related errors, for |
|
21521
e0a5d16a9cb9
Add notes that fromfd() and s.makefile() are Unix-specific.
Fred Drake <fdrake@acm.org>
parents:
21213
diff
changeset
|
106 \function{getaddrinfo()} and \function{getnameinfo()}. |
|
18995
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
107 The accompanying value is a pair \code{(\var{error}, \var{string})} |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
108 representing an error returned by a library call. |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
109 \var{string} represents the description of \var{error}, as returned |
|
21521
e0a5d16a9cb9
Add notes that fromfd() and s.makefile() are Unix-specific.
Fred Drake <fdrake@acm.org>
parents:
21213
diff
changeset
|
110 by the \cfunction{gai_strerror()} C function. |
|
31976
c5a552578344
note that the error code for socket.gaierror will be one of the EAI_*
Fred Drake <fdrake@acm.org>
parents:
31862
diff
changeset
|
111 The \var{error} value will match one of the \constant{EAI_*} constants |
|
c5a552578344
note that the error code for socket.gaierror will be one of the EAI_*
Fred Drake <fdrake@acm.org>
parents:
31862
diff
changeset
|
112 defined in this module. |
|
18995
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
113 \end{excdesc} |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
114 |
|
29665
d7626b80de95
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29560
diff
changeset
|
115 \begin{excdesc}{timeout} |
|
d7626b80de95
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29560
diff
changeset
|
116 This exception is raised when a timeout occurs on a socket which has |
|
d7626b80de95
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29560
diff
changeset
|
117 had timeouts enabled via a prior call to \method{settimeout()}. The |
|
d7626b80de95
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29560
diff
changeset
|
118 accompanying value is a string whose value is currently always ``timed |
|
d7626b80de95
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29560
diff
changeset
|
119 out''. |
|
d7626b80de95
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29560
diff
changeset
|
120 \versionadded{2.3} |
|
d7626b80de95
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29560
diff
changeset
|
121 \end{excdesc} |
|
d7626b80de95
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29560
diff
changeset
|
122 |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
123 \begin{datadesc}{AF_UNIX} |
|
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
124 \dataline{AF_INET} |
|
18995
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
125 \dataline{AF_INET6} |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
126 These constants represent the address (and protocol) families, |
| 7632 | 127 used for the first argument to \function{socket()}. If the |
| 128 \constant{AF_UNIX} constant is not defined then this protocol is | |
| 129 unsupported. | |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
130 \end{datadesc} |
|
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
131 |
|
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
132 \begin{datadesc}{SOCK_STREAM} |
|
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
133 \dataline{SOCK_DGRAM} |
|
1759
4d421f9e8373
* Doc/libsocket.tex (subsection{Socket Object Methods}):
Guido van Rossum <guido@python.org>
parents:
1750
diff
changeset
|
134 \dataline{SOCK_RAW} |
|
4d421f9e8373
* Doc/libsocket.tex (subsection{Socket Object Methods}):
Guido van Rossum <guido@python.org>
parents:
1750
diff
changeset
|
135 \dataline{SOCK_RDM} |
|
4d421f9e8373
* Doc/libsocket.tex (subsection{Socket Object Methods}):
Guido van Rossum <guido@python.org>
parents:
1750
diff
changeset
|
136 \dataline{SOCK_SEQPACKET} |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
137 These constants represent the socket types, |
| 7632 | 138 used for the second argument to \function{socket()}. |
| 139 (Only \constant{SOCK_STREAM} and | |
| 140 \constant{SOCK_DGRAM} appear to be generally useful.) | |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
141 \end{datadesc} |
|
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
142 |
|
2354
fbaf54169711
added lots of constants
Guido van Rossum <guido@python.org>
parents:
2064
diff
changeset
|
143 \begin{datadesc}{SO_*} |
|
fbaf54169711
added lots of constants
Guido van Rossum <guido@python.org>
parents:
2064
diff
changeset
|
144 \dataline{SOMAXCONN} |
|
fbaf54169711
added lots of constants
Guido van Rossum <guido@python.org>
parents:
2064
diff
changeset
|
145 \dataline{MSG_*} |
|
fbaf54169711
added lots of constants
Guido van Rossum <guido@python.org>
parents:
2064
diff
changeset
|
146 \dataline{SOL_*} |
|
fbaf54169711
added lots of constants
Guido van Rossum <guido@python.org>
parents:
2064
diff
changeset
|
147 \dataline{IPPROTO_*} |
|
fbaf54169711
added lots of constants
Guido van Rossum <guido@python.org>
parents:
2064
diff
changeset
|
148 \dataline{IPPORT_*} |
|
fbaf54169711
added lots of constants
Guido van Rossum <guido@python.org>
parents:
2064
diff
changeset
|
149 \dataline{INADDR_*} |
|
fbaf54169711
added lots of constants
Guido van Rossum <guido@python.org>
parents:
2064
diff
changeset
|
150 \dataline{IP_*} |
|
18995
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
151 \dataline{IPV6_*} |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
152 \dataline{EAI_*} |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
153 \dataline{AI_*} |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
154 \dataline{NI_*} |
|
21528
ac3ce1faec68
Fix the erroneous availability annotation for s.makefile() from the last
Fred Drake <fdrake@acm.org>
parents:
21521
diff
changeset
|
155 \dataline{TCP_*} |
|
2527
815dfaa6a778
small changes by Soren Larsen
Guido van Rossum <guido@python.org>
parents:
2453
diff
changeset
|
156 Many constants of these forms, documented in the \UNIX{} documentation on |
|
2354
fbaf54169711
added lots of constants
Guido van Rossum <guido@python.org>
parents:
2064
diff
changeset
|
157 sockets and/or the IP protocol, are also defined in the socket module. |
| 7632 | 158 They are generally used in arguments to the \method{setsockopt()} and |
| 159 \method{getsockopt()} methods of socket objects. In most cases, only | |
|
2527
815dfaa6a778
small changes by Soren Larsen
Guido van Rossum <guido@python.org>
parents:
2453
diff
changeset
|
160 those symbols that are defined in the \UNIX{} header files are defined; |
|
2354
fbaf54169711
added lots of constants
Guido van Rossum <guido@python.org>
parents:
2064
diff
changeset
|
161 for a few symbols, default values are provided. |
|
fbaf54169711
added lots of constants
Guido van Rossum <guido@python.org>
parents:
2064
diff
changeset
|
162 \end{datadesc} |
|
fbaf54169711
added lots of constants
Guido van Rossum <guido@python.org>
parents:
2064
diff
changeset
|
163 |
|
28818
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28330
diff
changeset
|
164 \begin{datadesc}{has_ipv6} |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28330
diff
changeset
|
165 This constant contains a boolean value which indicates if IPv6 is |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28330
diff
changeset
|
166 supported on this platform. |
|
28831
7012ca64bc74
Add versionadded for has_ipv6 attribute
Neal Norwitz <nnorwitz@gmail.com>
parents:
28818
diff
changeset
|
167 \versionadded{2.3} |
|
28818
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28330
diff
changeset
|
168 \end{datadesc} |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28330
diff
changeset
|
169 |
|
28844
cd82253f20b7
- add availability statements for some of the new APIs
Fred Drake <fdrake@acm.org>
parents:
28837
diff
changeset
|
170 \begin{funcdesc}{getaddrinfo}{host, port\optional{, family\optional{, |
|
cd82253f20b7
- add availability statements for some of the new APIs
Fred Drake <fdrake@acm.org>
parents:
28837
diff
changeset
|
171 socktype\optional{, proto\optional{, |
|
cd82253f20b7
- add availability statements for some of the new APIs
Fred Drake <fdrake@acm.org>
parents:
28837
diff
changeset
|
172 flags}}}}} |
|
18995
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
173 Resolves the \var{host}/\var{port} argument, into a sequence of |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
174 5-tuples that contain all the necessary argument for the sockets |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
175 manipulation. \var{host} is a domain name, a string representation of |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
176 IPv4/v6 address or \code{None}. |
|
28844
cd82253f20b7
- add availability statements for some of the new APIs
Fred Drake <fdrake@acm.org>
parents:
28837
diff
changeset
|
177 \var{port} is a string service name (like \code{'http'}), a numeric |
|
18995
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
178 port number or \code{None}. |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
179 |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
180 The rest of the arguments are optional and must be numeric if |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
181 specified. For \var{host} and \var{port}, by passing either an empty |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
182 string or \code{None}, you can pass \code{NULL} to the C API. The |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
183 \function{getaddrinfo()} function returns a list of 5-tuples with |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
184 the following structure: |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
185 |
|
28844
cd82253f20b7
- add availability statements for some of the new APIs
Fred Drake <fdrake@acm.org>
parents:
28837
diff
changeset
|
186 \code{(\var{family}, \var{socktype}, \var{proto}, \var{canonname}, |
|
cd82253f20b7
- add availability statements for some of the new APIs
Fred Drake <fdrake@acm.org>
parents:
28837
diff
changeset
|
187 \var{sockaddr})} |
|
18995
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
188 |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
189 \var{family}, \var{socktype}, \var{proto} are all integer and are meant to |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
190 be passed to the \function{socket()} function. |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
191 \var{canonname} is a string representing the canonical name of the \var{host}. |
|
28844
cd82253f20b7
- add availability statements for some of the new APIs
Fred Drake <fdrake@acm.org>
parents:
28837
diff
changeset
|
192 It can be a numeric IPv4/v6 address when \constant{AI_CANONNAME} is specified |
|
18995
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
193 for a numeric \var{host}. |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
194 \var{sockaddr} is a tuple describing a socket address, as described above. |
|
28844
cd82253f20b7
- add availability statements for some of the new APIs
Fred Drake <fdrake@acm.org>
parents:
28837
diff
changeset
|
195 See the source for the \refmodule{httplib} and other library modules |
|
18995
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
196 for a typical usage of the function. |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
197 \versionadded{2.2} |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
198 \end{funcdesc} |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
199 |
| 14010 | 200 \begin{funcdesc}{getfqdn}{\optional{name}} |
| 201 Return a fully qualified domain name for \var{name}. | |
| 202 If \var{name} is omitted or empty, it is interpreted as the local | |
| 203 host. To find the fully qualified name, the hostname returned by | |
| 204 \function{gethostbyaddr()} is checked, then aliases for the host, if | |
| 205 available. The first name which includes a period is selected. In | |
|
34739
0c82a7ef9554
Fix test_socket's test for socket.getfqdn() to also accept the result from
Brett Cannon <bcannon@gmail.com>
parents:
33280
diff
changeset
|
206 case no fully qualified domain name is available, the hostname as |
|
0c82a7ef9554
Fix test_socket's test for socket.getfqdn() to also accept the result from
Brett Cannon <bcannon@gmail.com>
parents:
33280
diff
changeset
|
207 returned by \function{gethostname()} is returned. |
|
14437
e348ed946d1f
Added a \versionadded statement to the getfqdn() description.
Fred Drake <fdrake@acm.org>
parents:
14010
diff
changeset
|
208 \versionadded{2.0} |
| 14010 | 209 \end{funcdesc} |
| 210 | |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
211 \begin{funcdesc}{gethostbyname}{hostname} |
|
18995
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
212 Translate a host name to IPv4 address format. The IPv4 address is |
|
21521
e0a5d16a9cb9
Add notes that fromfd() and s.makefile() are Unix-specific.
Fred Drake <fdrake@acm.org>
parents:
21213
diff
changeset
|
213 returned as a string, such as \code{'100.50.200.5'}. If the host name |
|
18995
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
214 is an IPv4 address itself it is returned unchanged. See |
| 10655 | 215 \function{gethostbyname_ex()} for a more complete interface. |
|
18995
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
216 \function{gethostbyname()} does not support IPv6 name resolution, and |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
217 \function{getaddrinfo()} should be used instead for IPv4/v6 dual stack support. |
|
8880
a9eb265d2f57
Document gethostbyname_ex().
Guido van Rossum <guido@python.org>
parents:
8716
diff
changeset
|
218 \end{funcdesc} |
|
a9eb265d2f57
Document gethostbyname_ex().
Guido van Rossum <guido@python.org>
parents:
8716
diff
changeset
|
219 |
|
a9eb265d2f57
Document gethostbyname_ex().
Guido van Rossum <guido@python.org>
parents:
8716
diff
changeset
|
220 \begin{funcdesc}{gethostbyname_ex}{hostname} |
|
18995
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
221 Translate a host name to IPv4 address format, extended interface. |
|
28844
cd82253f20b7
- add availability statements for some of the new APIs
Fred Drake <fdrake@acm.org>
parents:
28837
diff
changeset
|
222 Return a triple \code{(\var{hostname}, \var{aliaslist}, |
|
cd82253f20b7
- add availability statements for some of the new APIs
Fred Drake <fdrake@acm.org>
parents:
28837
diff
changeset
|
223 \var{ipaddrlist})} where |
|
cd82253f20b7
- add availability statements for some of the new APIs
Fred Drake <fdrake@acm.org>
parents:
28837
diff
changeset
|
224 \var{hostname} is the primary host name responding to the given |
|
cd82253f20b7
- add availability statements for some of the new APIs
Fred Drake <fdrake@acm.org>
parents:
28837
diff
changeset
|
225 \var{ip_address}, \var{aliaslist} is a (possibly empty) list of |
|
cd82253f20b7
- add availability statements for some of the new APIs
Fred Drake <fdrake@acm.org>
parents:
28837
diff
changeset
|
226 alternative host names for the same address, and \var{ipaddrlist} is |
|
18995
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
227 a list of IPv4 addresses for the same interface on the same |
|
8880
a9eb265d2f57
Document gethostbyname_ex().
Guido van Rossum <guido@python.org>
parents:
8716
diff
changeset
|
228 host (often but not always a single address). |
|
18995
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
229 \function{gethostbyname_ex()} does not support IPv6 name resolution, and |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
230 \function{getaddrinfo()} should be used instead for IPv4/v6 dual stack support. |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
231 \end{funcdesc} |
|
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
232 |
|
1759
4d421f9e8373
* Doc/libsocket.tex (subsection{Socket Object Methods}):
Guido van Rossum <guido@python.org>
parents:
1750
diff
changeset
|
233 \begin{funcdesc}{gethostname}{} |
|
1767
907605320a5f
Lots of small corrections by Andrew Kuchling (plus all new rotor docs)
Guido van Rossum <guido@python.org>
parents:
1759
diff
changeset
|
234 Return a string containing the hostname of the machine where |
|
18995
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
235 the Python interpreter is currently executing. |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
236 If you want to know the current machine's IP address, you may want to use |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
237 \code{gethostbyname(gethostname())}. |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
238 This operation assumes that there is a valid address-to-host mapping for |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
239 the host, and the assumption does not always hold. |
| 7632 | 240 Note: \function{gethostname()} doesn't always return the fully qualified |
| 241 domain name; use \code{gethostbyaddr(gethostname())} | |
|
4929
5126d4b819e9
Added warning that gethostname() doesn't always return fqdn, and show
Guido van Rossum <guido@python.org>
parents:
4882
diff
changeset
|
242 (see below). |
|
2064
280f31e6c653
copyright.tex: Add 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents:
1871
diff
changeset
|
243 \end{funcdesc} |
|
280f31e6c653
copyright.tex: Add 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents:
1871
diff
changeset
|
244 |
|
280f31e6c653
copyright.tex: Add 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents:
1871
diff
changeset
|
245 \begin{funcdesc}{gethostbyaddr}{ip_address} |
| 7632 | 246 Return a triple \code{(\var{hostname}, \var{aliaslist}, |
| 247 \var{ipaddrlist})} where \var{hostname} is the primary host name | |
| 248 responding to the given \var{ip_address}, \var{aliaslist} is a | |
| 249 (possibly empty) list of alternative host names for the same address, | |
|
18995
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
250 and \var{ipaddrlist} is a list of IPv4/v6 addresses for the same interface |
| 7632 | 251 on the same host (most likely containing only a single address). |
| 14010 | 252 To find the fully qualified domain name, use the function |
| 253 \function{getfqdn()}. | |
|
18995
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
254 \function{gethostbyaddr} supports both IPv4 and IPv6. |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
255 \end{funcdesc} |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
256 |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
257 \begin{funcdesc}{getnameinfo}{sockaddr, flags} |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
258 Translate a socket address \var{sockaddr} into a 2-tuple |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
259 \code{(\var{host}, \var{port})}. |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
260 Depending on the settings of \var{flags}, the result can contain a |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
261 fully-qualified domain name or numeric address representation in |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
262 \var{host}. Similarly, \var{port} can contain a string port name or a |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
263 numeric port number. |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
264 \versionadded{2.2} |
|
1759
4d421f9e8373
* Doc/libsocket.tex (subsection{Socket Object Methods}):
Guido van Rossum <guido@python.org>
parents:
1750
diff
changeset
|
265 \end{funcdesc} |
|
4d421f9e8373
* Doc/libsocket.tex (subsection{Socket Object Methods}):
Guido van Rossum <guido@python.org>
parents:
1750
diff
changeset
|
266 |
|
4784
e43362910a5e
Documented getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4576
diff
changeset
|
267 \begin{funcdesc}{getprotobyname}{protocolname} |
|
21521
e0a5d16a9cb9
Add notes that fromfd() and s.makefile() are Unix-specific.
Fred Drake <fdrake@acm.org>
parents:
21213
diff
changeset
|
268 Translate an Internet protocol name (for example, \code{'icmp'}) to a constant |
|
4784
e43362910a5e
Documented getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4576
diff
changeset
|
269 suitable for passing as the (optional) third argument to the |
| 7632 | 270 \function{socket()} function. This is usually only needed for sockets |
| 271 opened in ``raw'' mode (\constant{SOCK_RAW}); for the normal socket | |
| 272 modes, the correct protocol is chosen automatically if the protocol is | |
|
4784
e43362910a5e
Documented getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4576
diff
changeset
|
273 omitted or zero. |
|
e43362910a5e
Documented getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4576
diff
changeset
|
274 \end{funcdesc} |
|
e43362910a5e
Documented getprotobyname() interface.
Guido van Rossum <guido@python.org>
parents:
4576
diff
changeset
|
275 |
|
32429
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32231
diff
changeset
|
276 \begin{funcdesc}{getservbyname}{servicename\optional{, protocolname}} |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
277 Translate an Internet service name and protocol name to a port number |
|
32429
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32231
diff
changeset
|
278 for that service. The optional protocol name, if given, should be |
|
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32231
diff
changeset
|
279 \code{'tcp'} or \code{'udp'}, otherwise any protocol will match. |
|
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32231
diff
changeset
|
280 \end{funcdesc} |
|
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32231
diff
changeset
|
281 |
|
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32231
diff
changeset
|
282 \begin{funcdesc}{getservbyport}{port\optional{, protocolname}} |
|
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32231
diff
changeset
|
283 Translate an Internet port number and protocol name to a service name |
|
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32231
diff
changeset
|
284 for that service. The optional protocol name, if given, should be |
|
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32231
diff
changeset
|
285 \code{'tcp'} or \code{'udp'}, otherwise any protocol will match. |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
286 \end{funcdesc} |
|
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
287 |
|
31432
8f8bba0a75b4
update signature of the socket constructor
Fred Drake <fdrake@acm.org>
parents:
31181
diff
changeset
|
288 \begin{funcdesc}{socket}{\optional{family\optional{, |
|
8f8bba0a75b4
update signature of the socket constructor
Fred Drake <fdrake@acm.org>
parents:
31181
diff
changeset
|
289 type\optional{, proto}}}} |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
290 Create a new socket using the given address family, socket type and |
|
31432
8f8bba0a75b4
update signature of the socket constructor
Fred Drake <fdrake@acm.org>
parents:
31181
diff
changeset
|
291 protocol number. The address family should be \constant{AF_INET} (the |
|
8f8bba0a75b4
update signature of the socket constructor
Fred Drake <fdrake@acm.org>
parents:
31181
diff
changeset
|
292 default), \constant{AF_INET6} or \constant{AF_UNIX}. The socket type |
|
8f8bba0a75b4
update signature of the socket constructor
Fred Drake <fdrake@acm.org>
parents:
31181
diff
changeset
|
293 should be \constant{SOCK_STREAM} (the default), \constant{SOCK_DGRAM} |
|
8f8bba0a75b4
update signature of the socket constructor
Fred Drake <fdrake@acm.org>
parents:
31181
diff
changeset
|
294 or perhaps one of the other \samp{SOCK_} constants. The protocol |
|
8f8bba0a75b4
update signature of the socket constructor
Fred Drake <fdrake@acm.org>
parents:
31181
diff
changeset
|
295 number is usually zero and may be omitted in that case. |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
296 \end{funcdesc} |
|
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
297 |
|
20375
3ab3b535daf2
Document that keyfile and certfile are now optional.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20127
diff
changeset
|
298 \begin{funcdesc}{ssl}{sock\optional{, keyfile, certfile}} |
|
20082
18df32f6cea1
Added documentation for the SSL interface, contributed by Gerhard Häring.
Fred Drake <fdrake@acm.org>
parents:
18995
diff
changeset
|
299 Initiate a SSL connection over the socket \var{sock}. \var{keyfile} is |
|
18df32f6cea1
Added documentation for the SSL interface, contributed by Gerhard Häring.
Fred Drake <fdrake@acm.org>
parents:
18995
diff
changeset
|
300 the name of a PEM formatted file that contains your private |
|
18df32f6cea1
Added documentation for the SSL interface, contributed by Gerhard Häring.
Fred Drake <fdrake@acm.org>
parents:
18995
diff
changeset
|
301 key. \var{certfile} is a PEM formatted certificate chain file. On |
|
18df32f6cea1
Added documentation for the SSL interface, contributed by Gerhard Häring.
Fred Drake <fdrake@acm.org>
parents:
18995
diff
changeset
|
302 success, a new \class{SSLObject} is returned. |
|
18df32f6cea1
Added documentation for the SSL interface, contributed by Gerhard Häring.
Fred Drake <fdrake@acm.org>
parents:
18995
diff
changeset
|
303 |
|
20580
376ee174ecd0
Use the \note and \warning macros where appropriate.
Fred Drake <fdrake@acm.org>
parents:
20574
diff
changeset
|
304 \warning{This does not do any certificate verification!} |
|
20082
18df32f6cea1
Added documentation for the SSL interface, contributed by Gerhard Häring.
Fred Drake <fdrake@acm.org>
parents:
18995
diff
changeset
|
305 \end{funcdesc} |
|
18df32f6cea1
Added documentation for the SSL interface, contributed by Gerhard Häring.
Fred Drake <fdrake@acm.org>
parents:
18995
diff
changeset
|
306 |
|
33063
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32429
diff
changeset
|
307 \begin{funcdesc}{socketpair}{\optional{family\optional{, type\optional{, proto}}}} |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32429
diff
changeset
|
308 Build a pair of connected socket objects using the given address |
|
33280
826ad896a7a5
Patch #1015012. Improve markup and punctuation in libsocket.tex
Dave Cole <djc@object-craft.com.au>
parents:
33239
diff
changeset
|
309 family, socket type, and protocol number. Address family, socket type, |
|
33063
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32429
diff
changeset
|
310 and protocol number are as for the \function{socket()} function above. |
|
33280
826ad896a7a5
Patch #1015012. Improve markup and punctuation in libsocket.tex
Dave Cole <djc@object-craft.com.au>
parents:
33239
diff
changeset
|
311 The default family is \constant{AF_UNIX} if defined on the platform; |
|
826ad896a7a5
Patch #1015012. Improve markup and punctuation in libsocket.tex
Dave Cole <djc@object-craft.com.au>
parents:
33239
diff
changeset
|
312 otherwise, the default is \constant{AF_INET}. |
|
33239
fb9869044bba
Updated the socketpair() docstring and documentation to explain that the
Dave Cole <djc@object-craft.com.au>
parents:
33064
diff
changeset
|
313 Availability: \UNIX. \versionadded{2.4} |
|
33063
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32429
diff
changeset
|
314 \end{funcdesc} |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32429
diff
changeset
|
315 |
| 7632 | 316 \begin{funcdesc}{fromfd}{fd, family, type\optional{, proto}} |
|
37372
42312e5f11fd
Bug #1460564: document that socket.fromfd() duplicates the given
Georg Brandl <georg@python.org>
parents:
36127
diff
changeset
|
317 Duplicate the file descriptor \var{fd} (an integer as returned by a file |
|
42312e5f11fd
Bug #1460564: document that socket.fromfd() duplicates the given
Georg Brandl <georg@python.org>
parents:
36127
diff
changeset
|
318 object's \method{fileno()} method) and build a socket object from the |
|
42312e5f11fd
Bug #1460564: document that socket.fromfd() duplicates the given
Georg Brandl <georg@python.org>
parents:
36127
diff
changeset
|
319 result. Address family, socket type and protocol number are as for the |
|
42312e5f11fd
Bug #1460564: document that socket.fromfd() duplicates the given
Georg Brandl <georg@python.org>
parents:
36127
diff
changeset
|
320 \function{socket()} function above. |
|
42312e5f11fd
Bug #1460564: document that socket.fromfd() duplicates the given
Georg Brandl <georg@python.org>
parents:
36127
diff
changeset
|
321 The file descriptor should refer to a socket, but this is not |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
322 checked --- subsequent operations on the object may fail if the file |
|
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
323 descriptor is invalid. This function is rarely needed, but can be |
|
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
324 used to get or set socket options on a socket passed to a program as |
|
21521
e0a5d16a9cb9
Add notes that fromfd() and s.makefile() are Unix-specific.
Fred Drake <fdrake@acm.org>
parents:
21213
diff
changeset
|
325 standard input or output (such as a server started by the \UNIX{} inet |
|
23815
203d1412a7e8
Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents:
23730
diff
changeset
|
326 daemon). The socket is assumed to be in blocking mode. |
|
21521
e0a5d16a9cb9
Add notes that fromfd() and s.makefile() are Unix-specific.
Fred Drake <fdrake@acm.org>
parents:
21213
diff
changeset
|
327 Availability: \UNIX. |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
328 \end{funcdesc} |
|
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
329 |
|
4576
c3b0895c90fb
Added [nh]to[hn][sl]().
Guido van Rossum <guido@python.org>
parents:
2576
diff
changeset
|
330 \begin{funcdesc}{ntohl}{x} |
|
6783
c18501770895
Separated the definitions of ntohs(), ntohl(), htons(), htonl(). Separate
Fred Drake <fdrake@acm.org>
parents:
6587
diff
changeset
|
331 Convert 32-bit integers from network to host byte order. On machines |
|
c18501770895
Separated the definitions of ntohs(), ntohl(), htons(), htonl(). Separate
Fred Drake <fdrake@acm.org>
parents:
6587
diff
changeset
|
332 where the host byte order is the same as network byte order, this is a |
|
c18501770895
Separated the definitions of ntohs(), ntohl(), htons(), htonl(). Separate
Fred Drake <fdrake@acm.org>
parents:
6587
diff
changeset
|
333 no-op; otherwise, it performs a 4-byte swap operation. |
|
c18501770895
Separated the definitions of ntohs(), ntohl(), htons(), htonl(). Separate
Fred Drake <fdrake@acm.org>
parents:
6587
diff
changeset
|
334 \end{funcdesc} |
|
c18501770895
Separated the definitions of ntohs(), ntohl(), htons(), htonl(). Separate
Fred Drake <fdrake@acm.org>
parents:
6587
diff
changeset
|
335 |
|
c18501770895
Separated the definitions of ntohs(), ntohl(), htons(), htonl(). Separate
Fred Drake <fdrake@acm.org>
parents:
6587
diff
changeset
|
336 \begin{funcdesc}{ntohs}{x} |
|
c18501770895
Separated the definitions of ntohs(), ntohl(), htons(), htonl(). Separate
Fred Drake <fdrake@acm.org>
parents:
6587
diff
changeset
|
337 Convert 16-bit integers from network to host byte order. On machines |
|
c18501770895
Separated the definitions of ntohs(), ntohl(), htons(), htonl(). Separate
Fred Drake <fdrake@acm.org>
parents:
6587
diff
changeset
|
338 where the host byte order is the same as network byte order, this is a |
|
c18501770895
Separated the definitions of ntohs(), ntohl(), htons(), htonl(). Separate
Fred Drake <fdrake@acm.org>
parents:
6587
diff
changeset
|
339 no-op; otherwise, it performs a 2-byte swap operation. |
|
c18501770895
Separated the definitions of ntohs(), ntohl(), htons(), htonl(). Separate
Fred Drake <fdrake@acm.org>
parents:
6587
diff
changeset
|
340 \end{funcdesc} |
|
c18501770895
Separated the definitions of ntohs(), ntohl(), htons(), htonl(). Separate
Fred Drake <fdrake@acm.org>
parents:
6587
diff
changeset
|
341 |
|
c18501770895
Separated the definitions of ntohs(), ntohl(), htons(), htonl(). Separate
Fred Drake <fdrake@acm.org>
parents:
6587
diff
changeset
|
342 \begin{funcdesc}{htonl}{x} |
|
c18501770895
Separated the definitions of ntohs(), ntohl(), htons(), htonl(). Separate
Fred Drake <fdrake@acm.org>
parents:
6587
diff
changeset
|
343 Convert 32-bit integers from host to network byte order. On machines |
|
c18501770895
Separated the definitions of ntohs(), ntohl(), htons(), htonl(). Separate
Fred Drake <fdrake@acm.org>
parents:
6587
diff
changeset
|
344 where the host byte order is the same as network byte order, this is a |
|
c18501770895
Separated the definitions of ntohs(), ntohl(), htons(), htonl(). Separate
Fred Drake <fdrake@acm.org>
parents:
6587
diff
changeset
|
345 no-op; otherwise, it performs a 4-byte swap operation. |
|
c18501770895
Separated the definitions of ntohs(), ntohl(), htons(), htonl(). Separate
Fred Drake <fdrake@acm.org>
parents:
6587
diff
changeset
|
346 \end{funcdesc} |
|
c18501770895
Separated the definitions of ntohs(), ntohl(), htons(), htonl(). Separate
Fred Drake <fdrake@acm.org>
parents:
6587
diff
changeset
|
347 |
|
c18501770895
Separated the definitions of ntohs(), ntohl(), htons(), htonl(). Separate
Fred Drake <fdrake@acm.org>
parents:
6587
diff
changeset
|
348 \begin{funcdesc}{htons}{x} |
|
c18501770895
Separated the definitions of ntohs(), ntohl(), htons(), htonl(). Separate
Fred Drake <fdrake@acm.org>
parents:
6587
diff
changeset
|
349 Convert 16-bit integers from host to network byte order. On machines |
|
c18501770895
Separated the definitions of ntohs(), ntohl(), htons(), htonl(). Separate
Fred Drake <fdrake@acm.org>
parents:
6587
diff
changeset
|
350 where the host byte order is the same as network byte order, this is a |
|
c18501770895
Separated the definitions of ntohs(), ntohl(), htons(), htonl(). Separate
Fred Drake <fdrake@acm.org>
parents:
6587
diff
changeset
|
351 no-op; otherwise, it performs a 2-byte swap operation. |
|
4576
c3b0895c90fb
Added [nh]to[hn][sl]().
Guido van Rossum <guido@python.org>
parents:
2576
diff
changeset
|
352 \end{funcdesc} |
|
c3b0895c90fb
Added [nh]to[hn][sl]().
Guido van Rossum <guido@python.org>
parents:
2576
diff
changeset
|
353 |
|
11291
d970af0cece9
Added documentation for inet_aton() and inet_ntoa(), from Ben
Fred Drake <fdrake@acm.org>
parents:
11178
diff
changeset
|
354 \begin{funcdesc}{inet_aton}{ip_string} |
|
21521
e0a5d16a9cb9
Add notes that fromfd() and s.makefile() are Unix-specific.
Fred Drake <fdrake@acm.org>
parents:
21213
diff
changeset
|
355 Convert an IPv4 address from dotted-quad string format (for example, |
|
e0a5d16a9cb9
Add notes that fromfd() and s.makefile() are Unix-specific.
Fred Drake <fdrake@acm.org>
parents:
21213
diff
changeset
|
356 '123.45.67.89') to 32-bit packed binary format, as a string four |
|
28844
cd82253f20b7
- add availability statements for some of the new APIs
Fred Drake <fdrake@acm.org>
parents:
28837
diff
changeset
|
357 characters in length. This is useful when conversing with a program |
|
cd82253f20b7
- add availability statements for some of the new APIs
Fred Drake <fdrake@acm.org>
parents:
28837
diff
changeset
|
358 that uses the standard C library and needs objects of type |
|
cd82253f20b7
- add availability statements for some of the new APIs
Fred Drake <fdrake@acm.org>
parents:
28837
diff
changeset
|
359 \ctype{struct in_addr}, which is the C type for the 32-bit packed |
|
cd82253f20b7
- add availability statements for some of the new APIs
Fred Drake <fdrake@acm.org>
parents:
28837
diff
changeset
|
360 binary this function returns. |
|
11291
d970af0cece9
Added documentation for inet_aton() and inet_ntoa(), from Ben
Fred Drake <fdrake@acm.org>
parents:
11178
diff
changeset
|
361 |
|
18995
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
362 If the IPv4 address string passed to this function is invalid, |
|
11291
d970af0cece9
Added documentation for inet_aton() and inet_ntoa(), from Ben
Fred Drake <fdrake@acm.org>
parents:
11178
diff
changeset
|
363 \exception{socket.error} will be raised. Note that exactly what is |
|
d970af0cece9
Added documentation for inet_aton() and inet_ntoa(), from Ben
Fred Drake <fdrake@acm.org>
parents:
11178
diff
changeset
|
364 valid depends on the underlying C implementation of |
|
d970af0cece9
Added documentation for inet_aton() and inet_ntoa(), from Ben
Fred Drake <fdrake@acm.org>
parents:
11178
diff
changeset
|
365 \cfunction{inet_aton()}. |
|
18995
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
366 |
|
21528
ac3ce1faec68
Fix the erroneous availability annotation for s.makefile() from the last
Fred Drake <fdrake@acm.org>
parents:
21521
diff
changeset
|
367 \function{inet_aton()} does not support IPv6, and |
|
ac3ce1faec68
Fix the erroneous availability annotation for s.makefile() from the last
Fred Drake <fdrake@acm.org>
parents:
21521
diff
changeset
|
368 \function{getnameinfo()} should be used instead for IPv4/v6 dual stack |
|
ac3ce1faec68
Fix the erroneous availability annotation for s.makefile() from the last
Fred Drake <fdrake@acm.org>
parents:
21521
diff
changeset
|
369 support. |
|
11291
d970af0cece9
Added documentation for inet_aton() and inet_ntoa(), from Ben
Fred Drake <fdrake@acm.org>
parents:
11178
diff
changeset
|
370 \end{funcdesc} |
|
d970af0cece9
Added documentation for inet_aton() and inet_ntoa(), from Ben
Fred Drake <fdrake@acm.org>
parents:
11178
diff
changeset
|
371 |
|
d970af0cece9
Added documentation for inet_aton() and inet_ntoa(), from Ben
Fred Drake <fdrake@acm.org>
parents:
11178
diff
changeset
|
372 \begin{funcdesc}{inet_ntoa}{packed_ip} |
|
18995
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
373 Convert a 32-bit packed IPv4 address (a string four characters in |
|
28844
cd82253f20b7
- add availability statements for some of the new APIs
Fred Drake <fdrake@acm.org>
parents:
28837
diff
changeset
|
374 length) to its standard dotted-quad string representation (for |
|
cd82253f20b7
- add availability statements for some of the new APIs
Fred Drake <fdrake@acm.org>
parents:
28837
diff
changeset
|
375 example, '123.45.67.89'). This is useful when conversing with a |
|
cd82253f20b7
- add availability statements for some of the new APIs
Fred Drake <fdrake@acm.org>
parents:
28837
diff
changeset
|
376 program that uses the standard C library and needs objects of type |
|
cd82253f20b7
- add availability statements for some of the new APIs
Fred Drake <fdrake@acm.org>
parents:
28837
diff
changeset
|
377 \ctype{struct in_addr}, which is the C type for the 32-bit packed |
|
cd82253f20b7
- add availability statements for some of the new APIs
Fred Drake <fdrake@acm.org>
parents:
28837
diff
changeset
|
378 binary data this function takes as an argument. |
|
11291
d970af0cece9
Added documentation for inet_aton() and inet_ntoa(), from Ben
Fred Drake <fdrake@acm.org>
parents:
11178
diff
changeset
|
379 |
|
d970af0cece9
Added documentation for inet_aton() and inet_ntoa(), from Ben
Fred Drake <fdrake@acm.org>
parents:
11178
diff
changeset
|
380 If the string passed to this function is not exactly 4 bytes in |
|
d970af0cece9
Added documentation for inet_aton() and inet_ntoa(), from Ben
Fred Drake <fdrake@acm.org>
parents:
11178
diff
changeset
|
381 length, \exception{socket.error} will be raised. |
|
21528
ac3ce1faec68
Fix the erroneous availability annotation for s.makefile() from the last
Fred Drake <fdrake@acm.org>
parents:
21521
diff
changeset
|
382 \function{inet_ntoa()} does not support IPv6, and |
|
ac3ce1faec68
Fix the erroneous availability annotation for s.makefile() from the last
Fred Drake <fdrake@acm.org>
parents:
21521
diff
changeset
|
383 \function{getnameinfo()} should be used instead for IPv4/v6 dual stack |
|
ac3ce1faec68
Fix the erroneous availability annotation for s.makefile() from the last
Fred Drake <fdrake@acm.org>
parents:
21521
diff
changeset
|
384 support. |
|
11291
d970af0cece9
Added documentation for inet_aton() and inet_ntoa(), from Ben
Fred Drake <fdrake@acm.org>
parents:
11178
diff
changeset
|
385 \end{funcdesc} |
|
d970af0cece9
Added documentation for inet_aton() and inet_ntoa(), from Ben
Fred Drake <fdrake@acm.org>
parents:
11178
diff
changeset
|
386 |
|
28818
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28330
diff
changeset
|
387 \begin{funcdesc}{inet_pton}{address_family, ip_string} |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28330
diff
changeset
|
388 Convert an IP address from its family-specific string format to a packed, |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28330
diff
changeset
|
389 binary format. |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28330
diff
changeset
|
390 \function{inet_pton()} is useful when a library or network protocol calls for |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28330
diff
changeset
|
391 an object of type \ctype{struct in_addr} (similar to \function{inet_aton()}) |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28330
diff
changeset
|
392 or \ctype{struct in6_addr}. |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28330
diff
changeset
|
393 |
|
28844
cd82253f20b7
- add availability statements for some of the new APIs
Fred Drake <fdrake@acm.org>
parents:
28837
diff
changeset
|
394 Supported values for \var{address_family} are currently |
|
cd82253f20b7
- add availability statements for some of the new APIs
Fred Drake <fdrake@acm.org>
parents:
28837
diff
changeset
|
395 \constant{AF_INET} and \constant{AF_INET6}. |
|
cd82253f20b7
- add availability statements for some of the new APIs
Fred Drake <fdrake@acm.org>
parents:
28837
diff
changeset
|
396 If the IP address string \var{ip_string} is invalid, |
|
28818
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28330
diff
changeset
|
397 \exception{socket.error} will be raised. Note that exactly what is valid |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28330
diff
changeset
|
398 depends on both the value of \var{address_family} and the underlying |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28330
diff
changeset
|
399 implementation of \cfunction{inet_pton()}. |
|
28844
cd82253f20b7
- add availability statements for some of the new APIs
Fred Drake <fdrake@acm.org>
parents:
28837
diff
changeset
|
400 |
|
cd82253f20b7
- add availability statements for some of the new APIs
Fred Drake <fdrake@acm.org>
parents:
28837
diff
changeset
|
401 Availability: \UNIX{} (maybe not all platforms). |
|
28818
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28330
diff
changeset
|
402 \versionadded{2.3} |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28330
diff
changeset
|
403 \end{funcdesc} |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28330
diff
changeset
|
404 |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28330
diff
changeset
|
405 \begin{funcdesc}{inet_ntop}{address_family, packed_ip} |
|
28844
cd82253f20b7
- add availability statements for some of the new APIs
Fred Drake <fdrake@acm.org>
parents:
28837
diff
changeset
|
406 Convert a packed IP address (a string of some number of characters) to |
|
cd82253f20b7
- add availability statements for some of the new APIs
Fred Drake <fdrake@acm.org>
parents:
28837
diff
changeset
|
407 its standard, family-specific string representation (for example, |
|
cd82253f20b7
- add availability statements for some of the new APIs
Fred Drake <fdrake@acm.org>
parents:
28837
diff
changeset
|
408 \code{'7.10.0.5'} or \code{'5aef:2b::8'}) |
|
28837
c2a05e0785f1
Fix a copy-paste error: the paragraph about inet_ntop's use was copied
Guido van Rossum <guido@python.org>
parents:
28831
diff
changeset
|
409 \function{inet_ntop()} is useful when a library or network protocol returns |
|
c2a05e0785f1
Fix a copy-paste error: the paragraph about inet_ntop's use was copied
Guido van Rossum <guido@python.org>
parents:
28831
diff
changeset
|
410 an object of type \ctype{struct in_addr} (similar to \function{inet_ntoa()}) |
|
28818
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28330
diff
changeset
|
411 or \ctype{struct in6_addr}. |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28330
diff
changeset
|
412 |
|
28844
cd82253f20b7
- add availability statements for some of the new APIs
Fred Drake <fdrake@acm.org>
parents:
28837
diff
changeset
|
413 Supported values for \var{address_family} are currently |
|
cd82253f20b7
- add availability statements for some of the new APIs
Fred Drake <fdrake@acm.org>
parents:
28837
diff
changeset
|
414 \constant{AF_INET} and \constant{AF_INET6}. |
|
cd82253f20b7
- add availability statements for some of the new APIs
Fred Drake <fdrake@acm.org>
parents:
28837
diff
changeset
|
415 If the string \var{packed_ip} is not the correct length for the |
|
cd82253f20b7
- add availability statements for some of the new APIs
Fred Drake <fdrake@acm.org>
parents:
28837
diff
changeset
|
416 specified address family, \exception{ValueError} will be raised. A |
|
cd82253f20b7
- add availability statements for some of the new APIs
Fred Drake <fdrake@acm.org>
parents:
28837
diff
changeset
|
417 \exception{socket.error} is raised for errors from the call to |
|
28818
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28330
diff
changeset
|
418 \function{inet_ntop()}. |
|
28844
cd82253f20b7
- add availability statements for some of the new APIs
Fred Drake <fdrake@acm.org>
parents:
28837
diff
changeset
|
419 |
|
cd82253f20b7
- add availability statements for some of the new APIs
Fred Drake <fdrake@acm.org>
parents:
28837
diff
changeset
|
420 Availability: \UNIX{} (maybe not all platforms). |
|
28818
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28330
diff
changeset
|
421 \versionadded{2.3} |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28330
diff
changeset
|
422 \end{funcdesc} |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
28330
diff
changeset
|
423 |
|
28330
02ce22830ab9
add descriptions of {get,set}defaulttimeout.
Skip Montanaro <skip@pobox.com>
parents:
23815
diff
changeset
|
424 \begin{funcdesc}{getdefaulttimeout}{} |
|
02ce22830ab9
add descriptions of {get,set}defaulttimeout.
Skip Montanaro <skip@pobox.com>
parents:
23815
diff
changeset
|
425 Return the default timeout in floating seconds for new socket objects. |
|
02ce22830ab9
add descriptions of {get,set}defaulttimeout.
Skip Montanaro <skip@pobox.com>
parents:
23815
diff
changeset
|
426 A value of \code{None} indicates that new socket objects have no timeout. |
|
02ce22830ab9
add descriptions of {get,set}defaulttimeout.
Skip Montanaro <skip@pobox.com>
parents:
23815
diff
changeset
|
427 When the socket module is first imported, the default is \code{None}. |
|
02ce22830ab9
add descriptions of {get,set}defaulttimeout.
Skip Montanaro <skip@pobox.com>
parents:
23815
diff
changeset
|
428 \versionadded{2.3} |
|
02ce22830ab9
add descriptions of {get,set}defaulttimeout.
Skip Montanaro <skip@pobox.com>
parents:
23815
diff
changeset
|
429 \end{funcdesc} |
|
02ce22830ab9
add descriptions of {get,set}defaulttimeout.
Skip Montanaro <skip@pobox.com>
parents:
23815
diff
changeset
|
430 |
|
02ce22830ab9
add descriptions of {get,set}defaulttimeout.
Skip Montanaro <skip@pobox.com>
parents:
23815
diff
changeset
|
431 \begin{funcdesc}{setdefaulttimeout}{timeout} |
|
02ce22830ab9
add descriptions of {get,set}defaulttimeout.
Skip Montanaro <skip@pobox.com>
parents:
23815
diff
changeset
|
432 Set the default timeout in floating seconds for new socket objects. |
|
02ce22830ab9
add descriptions of {get,set}defaulttimeout.
Skip Montanaro <skip@pobox.com>
parents:
23815
diff
changeset
|
433 A value of \code{None} indicates that new socket objects have no timeout. |
|
02ce22830ab9
add descriptions of {get,set}defaulttimeout.
Skip Montanaro <skip@pobox.com>
parents:
23815
diff
changeset
|
434 When the socket module is first imported, the default is \code{None}. |
|
02ce22830ab9
add descriptions of {get,set}defaulttimeout.
Skip Montanaro <skip@pobox.com>
parents:
23815
diff
changeset
|
435 \versionadded{2.3} |
|
02ce22830ab9
add descriptions of {get,set}defaulttimeout.
Skip Montanaro <skip@pobox.com>
parents:
23815
diff
changeset
|
436 \end{funcdesc} |
|
02ce22830ab9
add descriptions of {get,set}defaulttimeout.
Skip Montanaro <skip@pobox.com>
parents:
23815
diff
changeset
|
437 |
| 6482 | 438 \begin{datadesc}{SocketType} |
|
5574
84d7cc5e63cd
Added description of socket_type.
Guido van Rossum <guido@python.org>
parents:
5461
diff
changeset
|
439 This is a Python type object that represents the socket object type. |
| 7632 | 440 It is the same as \code{type(socket(...))}. |
|
5574
84d7cc5e63cd
Added description of socket_type.
Guido van Rossum <guido@python.org>
parents:
5461
diff
changeset
|
441 \end{datadesc} |
|
84d7cc5e63cd
Added description of socket_type.
Guido van Rossum <guido@python.org>
parents:
5461
diff
changeset
|
442 |
|
13386
3f08bedc1c26
Clean up markup to be more like recommended practice; only small changes
Fred Drake <fdrake@acm.org>
parents:
13178
diff
changeset
|
443 |
|
3f08bedc1c26
Clean up markup to be more like recommended practice; only small changes
Fred Drake <fdrake@acm.org>
parents:
13178
diff
changeset
|
444 \begin{seealso} |
|
3f08bedc1c26
Clean up markup to be more like recommended practice; only small changes
Fred Drake <fdrake@acm.org>
parents:
13178
diff
changeset
|
445 \seemodule{SocketServer}{Classes that simplify writing network servers.} |
|
3f08bedc1c26
Clean up markup to be more like recommended practice; only small changes
Fred Drake <fdrake@acm.org>
parents:
13178
diff
changeset
|
446 \end{seealso} |
|
3f08bedc1c26
Clean up markup to be more like recommended practice; only small changes
Fred Drake <fdrake@acm.org>
parents:
13178
diff
changeset
|
447 |
|
3f08bedc1c26
Clean up markup to be more like recommended practice; only small changes
Fred Drake <fdrake@acm.org>
parents:
13178
diff
changeset
|
448 |
|
11178
245d2b605036
Add index entry "I/O control, buffering" for makefile().
Fred Drake <fdrake@acm.org>
parents:
10836
diff
changeset
|
449 \subsection{Socket Objects \label{socket-objects}} |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
450 |
|
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
451 Socket objects have the following methods. Except for |
| 7632 | 452 \method{makefile()} these correspond to \UNIX{} system calls |
| 453 applicable to sockets. | |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
454 |
|
7823
0575d5a17218
Use {methoddesc} as appropriate.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
455 \begin{methoddesc}[socket]{accept}{} |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
456 Accept a connection. |
|
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
457 The socket must be bound to an address and listening for connections. |
|
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
458 The return value is a pair \code{(\var{conn}, \var{address})} |
|
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
459 where \var{conn} is a \emph{new} socket object usable to send and |
|
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
460 receive data on the connection, and \var{address} is the address bound |
|
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
461 to the socket on the other end of the connection. |
|
7823
0575d5a17218
Use {methoddesc} as appropriate.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
462 \end{methoddesc} |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
463 |
|
7823
0575d5a17218
Use {methoddesc} as appropriate.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
464 \begin{methoddesc}[socket]{bind}{address} |
|
1682
2bcddc905da0
clarify the meaning of address for those methods that or return addresses
Guido van Rossum <guido@python.org>
parents:
1567
diff
changeset
|
465 Bind the socket to \var{address}. The socket must not already be bound. |
|
12230
7bf8b10ce2ab
Added notes about the eventual disappearance of two-parameter bind(),
Fred Drake <fdrake@acm.org>
parents:
12223
diff
changeset
|
466 (The format of \var{address} depends on the address family --- see |
|
20580
376ee174ecd0
Use the \note and \warning macros where appropriate.
Fred Drake <fdrake@acm.org>
parents:
20574
diff
changeset
|
467 above.) \note{This method has historically accepted a pair |
|
12230
7bf8b10ce2ab
Added notes about the eventual disappearance of two-parameter bind(),
Fred Drake <fdrake@acm.org>
parents:
12223
diff
changeset
|
468 of parameters for \constant{AF_INET} addresses instead of only a |
|
31862
dbd3fc214b66
#928751, fix typos in socket doc
Neal Norwitz <nnorwitz@gmail.com>
parents:
31432
diff
changeset
|
469 tuple. This was never intentional and is no longer available in |
|
dbd3fc214b66
#928751, fix typos in socket doc
Neal Norwitz <nnorwitz@gmail.com>
parents:
31432
diff
changeset
|
470 Python 2.0 and later.} |
|
7823
0575d5a17218
Use {methoddesc} as appropriate.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
471 \end{methoddesc} |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
472 |
|
7823
0575d5a17218
Use {methoddesc} as appropriate.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
473 \begin{methoddesc}[socket]{close}{} |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
474 Close the socket. All future operations on the socket object will fail. |
|
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
475 The remote end will receive no more data (after queued data is flushed). |
|
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
476 Sockets are automatically closed when they are garbage-collected. |
|
7823
0575d5a17218
Use {methoddesc} as appropriate.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
477 \end{methoddesc} |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
478 |
|
7823
0575d5a17218
Use {methoddesc} as appropriate.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
479 \begin{methoddesc}[socket]{connect}{address} |
|
1682
2bcddc905da0
clarify the meaning of address for those methods that or return addresses
Guido van Rossum <guido@python.org>
parents:
1567
diff
changeset
|
480 Connect to a remote socket at \var{address}. |
| 7632 | 481 (The format of \var{address} depends on the address family --- see |
|
20580
376ee174ecd0
Use the \note and \warning macros where appropriate.
Fred Drake <fdrake@acm.org>
parents:
20574
diff
changeset
|
482 above.) \note{This method has historically accepted a pair |
|
12230
7bf8b10ce2ab
Added notes about the eventual disappearance of two-parameter bind(),
Fred Drake <fdrake@acm.org>
parents:
12223
diff
changeset
|
483 of parameters for \constant{AF_INET} addresses instead of only a |
|
15800
3a260274bcc6
SourceForge patch #103140, checked in at fdrake's invitation. Minor fixes and
Eric S. Raymond <esr@thyrsus.com>
parents:
15146
diff
changeset
|
484 tuple. This was never intentional and is no longer available in |
|
20580
376ee174ecd0
Use the \note and \warning macros where appropriate.
Fred Drake <fdrake@acm.org>
parents:
20574
diff
changeset
|
485 Python 2.0 and later.} |
|
7823
0575d5a17218
Use {methoddesc} as appropriate.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
486 \end{methoddesc} |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
487 |
|
7823
0575d5a17218
Use {methoddesc} as appropriate.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
488 \begin{methoddesc}[socket]{connect_ex}{address} |
|
6804
e224c41bdac6
Fix a little mess (Likecode{...} -> Like \code{...}) in recently added text.
Guido van Rossum <guido@python.org>
parents:
6783
diff
changeset
|
489 Like \code{connect(\var{address})}, but return an error indicator |
|
10836
efd1573a4b03
Updated connect_ex() documentation based on comments in the newgroup
Fred Drake <fdrake@acm.org>
parents:
10655
diff
changeset
|
490 instead of raising an exception for errors returned by the C-level |
|
efd1573a4b03
Updated connect_ex() documentation based on comments in the newgroup
Fred Drake <fdrake@acm.org>
parents:
10655
diff
changeset
|
491 \cfunction{connect()} call (other problems, such as ``host not found,'' |
|
efd1573a4b03
Updated connect_ex() documentation based on comments in the newgroup
Fred Drake <fdrake@acm.org>
parents:
10655
diff
changeset
|
492 can still raise exceptions). The error indicator is \code{0} if the |
| 7632 | 493 operation succeeded, otherwise the value of the \cdata{errno} |
|
21521
e0a5d16a9cb9
Add notes that fromfd() and s.makefile() are Unix-specific.
Fred Drake <fdrake@acm.org>
parents:
21213
diff
changeset
|
494 variable. This is useful to support, for example, asynchronous connects. |
|
20580
376ee174ecd0
Use the \note and \warning macros where appropriate.
Fred Drake <fdrake@acm.org>
parents:
20574
diff
changeset
|
495 \note{This method has historically accepted a pair of |
|
12230
7bf8b10ce2ab
Added notes about the eventual disappearance of two-parameter bind(),
Fred Drake <fdrake@acm.org>
parents:
12223
diff
changeset
|
496 parameters for \constant{AF_INET} addresses instead of only a tuple. |
|
31862
dbd3fc214b66
#928751, fix typos in socket doc
Neal Norwitz <nnorwitz@gmail.com>
parents:
31432
diff
changeset
|
497 This was never intentional and is no longer available in Python |
|
20580
376ee174ecd0
Use the \note and \warning macros where appropriate.
Fred Drake <fdrake@acm.org>
parents:
20574
diff
changeset
|
498 2.0 and later.} |
|
7823
0575d5a17218
Use {methoddesc} as appropriate.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
499 \end{methoddesc} |
|
6587
e0e667bbc971
Document s.connect_ex(), which does not raise an exception on error.
Guido van Rossum <guido@python.org>
parents:
6482
diff
changeset
|
500 |
|
7823
0575d5a17218
Use {methoddesc} as appropriate.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
501 \begin{methoddesc}[socket]{fileno}{} |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
502 Return the socket's file descriptor (a small integer). This is useful |
| 7632 | 503 with \function{select.select()}. |
|
30048
2cfaca62a990
Add note about fileno not being usable as a normal file descriptor in Windows.
Brett Cannon <bcannon@gmail.com>
parents:
29949
diff
changeset
|
504 |
|
2cfaca62a990
Add note about fileno not being usable as a normal file descriptor in Windows.
Brett Cannon <bcannon@gmail.com>
parents:
29949
diff
changeset
|
505 Under Windows the small integer returned by this method cannot be used where |
|
2cfaca62a990
Add note about fileno not being usable as a normal file descriptor in Windows.
Brett Cannon <bcannon@gmail.com>
parents:
29949
diff
changeset
|
506 a file descriptor can be used (such as \function{os.fdopen()}). \UNIX{} does |
|
2cfaca62a990
Add note about fileno not being usable as a normal file descriptor in Windows.
Brett Cannon <bcannon@gmail.com>
parents:
29949
diff
changeset
|
507 not have this limitation. |
|
7823
0575d5a17218
Use {methoddesc} as appropriate.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
508 \end{methoddesc} |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
509 |
|
7823
0575d5a17218
Use {methoddesc} as appropriate.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
510 \begin{methoddesc}[socket]{getpeername}{} |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
511 Return the remote address to which the socket is connected. This is |
|
18995
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
512 useful to find out the port number of a remote IPv4/v6 socket, for instance. |
|
2453
cdd3a721b40e
a few typographical changes (e.g. -- => ---) and lots of new stuff in the WWW chapter
Guido van Rossum <guido@python.org>
parents:
2447
diff
changeset
|
513 (The format of the address returned depends on the address family --- |
|
1759
4d421f9e8373
* Doc/libsocket.tex (subsection{Socket Object Methods}):
Guido van Rossum <guido@python.org>
parents:
1750
diff
changeset
|
514 see above.) On some systems this function is not supported. |
|
7823
0575d5a17218
Use {methoddesc} as appropriate.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
515 \end{methoddesc} |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
516 |
|
7823
0575d5a17218
Use {methoddesc} as appropriate.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
517 \begin{methoddesc}[socket]{getsockname}{} |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
518 Return the socket's own address. This is useful to find out the port |
|
18995
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
519 number of an IPv4/v6 socket, for instance. |
|
2453
cdd3a721b40e
a few typographical changes (e.g. -- => ---) and lots of new stuff in the WWW chapter
Guido van Rossum <guido@python.org>
parents:
2447
diff
changeset
|
520 (The format of the address returned depends on the address family --- |
|
1682
2bcddc905da0
clarify the meaning of address for those methods that or return addresses
Guido van Rossum <guido@python.org>
parents:
1567
diff
changeset
|
521 see above.) |
|
7823
0575d5a17218
Use {methoddesc} as appropriate.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
522 \end{methoddesc} |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
523 |
|
7823
0575d5a17218
Use {methoddesc} as appropriate.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
524 \begin{methoddesc}[socket]{getsockopt}{level, optname\optional{, buflen}} |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
525 Return the value of the given socket option (see the \UNIX{} man page |
| 7632 | 526 \manpage{getsockopt}{2}). The needed symbolic constants |
| 527 (\constant{SO_*} etc.) are defined in this module. If \var{buflen} | |
|
2576
f47bc5554418
mass changes; fix titles; add examples; correct typos; clarifications;
Guido van Rossum <guido@python.org>
parents:
2527
diff
changeset
|
528 is absent, an integer option is assumed and its integer value |
|
2447
73499a667e78
changes refs to SO_* symbols
Guido van Rossum <guido@python.org>
parents:
2354
diff
changeset
|
529 is returned by the function. If \var{buflen} is present, it specifies |
|
73499a667e78
changes refs to SO_* symbols
Guido van Rossum <guido@python.org>
parents:
2354
diff
changeset
|
530 the maximum length of the buffer used to receive the option in, and |
|
2576
f47bc5554418
mass changes; fix titles; add examples; correct typos; clarifications;
Guido van Rossum <guido@python.org>
parents:
2527
diff
changeset
|
531 this buffer is returned as a string. It is up to the caller to decode |
|
2447
73499a667e78
changes refs to SO_* symbols
Guido van Rossum <guido@python.org>
parents:
2354
diff
changeset
|
532 the contents of the buffer (see the optional built-in module |
| 10655 | 533 \refmodule{struct} for a way to decode C structures encoded as strings). |
|
7823
0575d5a17218
Use {methoddesc} as appropriate.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
534 \end{methoddesc} |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
535 |
|
7823
0575d5a17218
Use {methoddesc} as appropriate.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
536 \begin{methoddesc}[socket]{listen}{backlog} |
|
2576
f47bc5554418
mass changes; fix titles; add examples; correct typos; clarifications;
Guido van Rossum <guido@python.org>
parents:
2527
diff
changeset
|
537 Listen for connections made to the socket. The \var{backlog} argument |
|
f47bc5554418
mass changes; fix titles; add examples; correct typos; clarifications;
Guido van Rossum <guido@python.org>
parents:
2527
diff
changeset
|
538 specifies the maximum number of queued connections and should be at |
|
f47bc5554418
mass changes; fix titles; add examples; correct typos; clarifications;
Guido van Rossum <guido@python.org>
parents:
2527
diff
changeset
|
539 least 1; the maximum value is system-dependent (usually 5). |
|
7823
0575d5a17218
Use {methoddesc} as appropriate.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
540 \end{methoddesc} |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
541 |
|
7823
0575d5a17218
Use {methoddesc} as appropriate.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
542 \begin{methoddesc}[socket]{makefile}{\optional{mode\optional{, bufsize}}} |
|
2576
f47bc5554418
mass changes; fix titles; add examples; correct typos; clarifications;
Guido van Rossum <guido@python.org>
parents:
2527
diff
changeset
|
543 Return a \dfn{file object} associated with the socket. (File objects |
|
11178
245d2b605036
Add index entry "I/O control, buffering" for makefile().
Fred Drake <fdrake@acm.org>
parents:
10836
diff
changeset
|
544 are described in \ref{bltin-file-objects}, ``File Objects.'') |
| 7632 | 545 The file object references a \cfunction{dup()}ped version of the |
| 546 socket file descriptor, so the file object and socket object may be | |
|
11178
245d2b605036
Add index entry "I/O control, buffering" for makefile().
Fred Drake <fdrake@acm.org>
parents:
10836
diff
changeset
|
547 closed or garbage-collected independently. |
|
23730
af8d40e4c377
Clarify the interaction between timeout/non-blocking mode, makefile
Guido van Rossum <guido@python.org>
parents:
23729
diff
changeset
|
548 The socket should be in blocking mode. |
|
11178
245d2b605036
Add index entry "I/O control, buffering" for makefile().
Fred Drake <fdrake@acm.org>
parents:
10836
diff
changeset
|
549 \index{I/O control!buffering}The optional \var{mode} |
| 7632 | 550 and \var{bufsize} arguments are interpreted the same way as by the |
|
20574
5af6c89c8cb7
When stating that some parameters to makefile() are similar to the open()
Fred Drake <fdrake@acm.org>
parents:
20375
diff
changeset
|
551 built-in \function{file()} function; see ``Built-in Functions'' |
|
5af6c89c8cb7
When stating that some parameters to makefile() are similar to the open()
Fred Drake <fdrake@acm.org>
parents:
20375
diff
changeset
|
552 (section \ref{built-in-funcs}) for more information. |
|
7823
0575d5a17218
Use {methoddesc} as appropriate.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
553 \end{methoddesc} |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
554 |
|
7823
0575d5a17218
Use {methoddesc} as appropriate.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
555 \begin{methoddesc}[socket]{recv}{bufsize\optional{, flags}} |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
556 Receive data from the socket. The return value is a string representing |
|
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
557 the data received. The maximum amount of data to be received |
|
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
558 at once is specified by \var{bufsize}. See the \UNIX{} manual page |
| 7632 | 559 \manpage{recv}{2} for the meaning of the optional argument |
| 560 \var{flags}; it defaults to zero. | |
|
36127
76d511972616
Bug #756104 (backport): document that bufsize in socket.recv() should be small
Georg Brandl <georg@python.org>
parents:
35672
diff
changeset
|
561 \note{For best match with hardware and network realities, the value of |
|
76d511972616
Bug #756104 (backport): document that bufsize in socket.recv() should be small
Georg Brandl <georg@python.org>
parents:
35672
diff
changeset
|
562 \var{bufsize} should be a relatively small power of 2, for example, 4096.} |
|
7823
0575d5a17218
Use {methoddesc} as appropriate.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
563 \end{methoddesc} |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
564 |
|
7823
0575d5a17218
Use {methoddesc} as appropriate.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
565 \begin{methoddesc}[socket]{recvfrom}{bufsize\optional{, flags}} |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
566 Receive data from the socket. The return value is a pair |
|
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
567 \code{(\var{string}, \var{address})} where \var{string} is a string |
|
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
568 representing the data received and \var{address} is the address of the |
|
2576
f47bc5554418
mass changes; fix titles; add examples; correct typos; clarifications;
Guido van Rossum <guido@python.org>
parents:
2527
diff
changeset
|
569 socket sending the data. The optional \var{flags} argument has the |
| 7632 | 570 same meaning as for \method{recv()} above. |
|
2453
cdd3a721b40e
a few typographical changes (e.g. -- => ---) and lots of new stuff in the WWW chapter
Guido van Rossum <guido@python.org>
parents:
2447
diff
changeset
|
571 (The format of \var{address} depends on the address family --- see above.) |
|
7823
0575d5a17218
Use {methoddesc} as appropriate.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
572 \end{methoddesc} |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
573 |
|
7823
0575d5a17218
Use {methoddesc} as appropriate.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
574 \begin{methoddesc}[socket]{send}{string\optional{, flags}} |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
575 Send data to the socket. The socket must be connected to a remote |
|
2576
f47bc5554418
mass changes; fix titles; add examples; correct typos; clarifications;
Guido van Rossum <guido@python.org>
parents:
2527
diff
changeset
|
576 socket. The optional \var{flags} argument has the same meaning as for |
| 7632 | 577 \method{recv()} above. Returns the number of bytes sent. |
|
21213
3b09ea723ece
Added documentation of the sendall() method, and a note to the send() method
Fred Drake <fdrake@acm.org>
parents:
20580
diff
changeset
|
578 Applications are responsible for checking that all data has been sent; |
|
3b09ea723ece
Added documentation of the sendall() method, and a note to the send() method
Fred Drake <fdrake@acm.org>
parents:
20580
diff
changeset
|
579 if only some of the data was transmitted, the application needs to |
|
3b09ea723ece
Added documentation of the sendall() method, and a note to the send() method
Fred Drake <fdrake@acm.org>
parents:
20580
diff
changeset
|
580 attempt delivery of the remaining data. |
|
3b09ea723ece
Added documentation of the sendall() method, and a note to the send() method
Fred Drake <fdrake@acm.org>
parents:
20580
diff
changeset
|
581 \end{methoddesc} |
|
3b09ea723ece
Added documentation of the sendall() method, and a note to the send() method
Fred Drake <fdrake@acm.org>
parents:
20580
diff
changeset
|
582 |
|
3b09ea723ece
Added documentation of the sendall() method, and a note to the send() method
Fred Drake <fdrake@acm.org>
parents:
20580
diff
changeset
|
583 \begin{methoddesc}[socket]{sendall}{string\optional{, flags}} |
|
3b09ea723ece
Added documentation of the sendall() method, and a note to the send() method
Fred Drake <fdrake@acm.org>
parents:
20580
diff
changeset
|
584 Send data to the socket. The socket must be connected to a remote |
|
3b09ea723ece
Added documentation of the sendall() method, and a note to the send() method
Fred Drake <fdrake@acm.org>
parents:
20580
diff
changeset
|
585 socket. The optional \var{flags} argument has the same meaning as for |
|
3b09ea723ece
Added documentation of the sendall() method, and a note to the send() method
Fred Drake <fdrake@acm.org>
parents:
20580
diff
changeset
|
586 \method{recv()} above. Unlike \method{send()}, this method continues |
|
3b09ea723ece
Added documentation of the sendall() method, and a note to the send() method
Fred Drake <fdrake@acm.org>
parents:
20580
diff
changeset
|
587 to send data from \var{string} until either all data has been sent or |
|
3b09ea723ece
Added documentation of the sendall() method, and a note to the send() method
Fred Drake <fdrake@acm.org>
parents:
20580
diff
changeset
|
588 an error occurs. \code{None} is returned on success. On error, an |
|
3b09ea723ece
Added documentation of the sendall() method, and a note to the send() method
Fred Drake <fdrake@acm.org>
parents:
20580
diff
changeset
|
589 exception is raised, and there is no way to determine how much data, |
|
3b09ea723ece
Added documentation of the sendall() method, and a note to the send() method
Fred Drake <fdrake@acm.org>
parents:
20580
diff
changeset
|
590 if any, was successfully sent. |
|
7823
0575d5a17218
Use {methoddesc} as appropriate.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
591 \end{methoddesc} |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
592 |
|
7823
0575d5a17218
Use {methoddesc} as appropriate.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
593 \begin{methoddesc}[socket]{sendto}{string\optional{, flags}, address} |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
594 Send data to the socket. The socket should not be connected to a |
|
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
595 remote socket, since the destination socket is specified by |
| 7632 | 596 \var{address}. The optional \var{flags} argument has the same |
| 597 meaning as for \method{recv()} above. Return the number of bytes sent. | |
|
2453
cdd3a721b40e
a few typographical changes (e.g. -- => ---) and lots of new stuff in the WWW chapter
Guido van Rossum <guido@python.org>
parents:
2447
diff
changeset
|
598 (The format of \var{address} depends on the address family --- see above.) |
|
7823
0575d5a17218
Use {methoddesc} as appropriate.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
599 \end{methoddesc} |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
600 |
|
7823
0575d5a17218
Use {methoddesc} as appropriate.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
601 \begin{methoddesc}[socket]{setblocking}{flag} |
|
1871
10a12473ee93
added Tommy Burnette's setblocking() method
Guido van Rossum <guido@python.org>
parents:
1767
diff
changeset
|
602 Set blocking or non-blocking mode of the socket: if \var{flag} is 0, |
|
10a12473ee93
added Tommy Burnette's setblocking() method
Guido van Rossum <guido@python.org>
parents:
1767
diff
changeset
|
603 the socket is set to non-blocking, else to blocking mode. Initially |
|
10a12473ee93
added Tommy Burnette's setblocking() method
Guido van Rossum <guido@python.org>
parents:
1767
diff
changeset
|
604 all sockets are in blocking mode. In non-blocking mode, if a |
| 10655 | 605 \method{recv()} call doesn't find any data, or if a |
| 606 \method{send()} call can't immediately dispose of the data, a | |
| 607 \exception{error} exception is raised; in blocking mode, the calls | |
| 608 block until they can proceed. | |
|
23815
203d1412a7e8
Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents:
23730
diff
changeset
|
609 \code{s.setblocking(0)} is equivalent to \code{s.settimeout(0)}; |
|
203d1412a7e8
Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents:
23730
diff
changeset
|
610 \code{s.setblocking(1)} is equivalent to \code{s.settimeout(None)}. |
|
7823
0575d5a17218
Use {methoddesc} as appropriate.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
611 \end{methoddesc} |
|
1871
10a12473ee93
added Tommy Burnette's setblocking() method
Guido van Rossum <guido@python.org>
parents:
1767
diff
changeset
|
612 |
|
23717
77154cef29d1
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
21528
diff
changeset
|
613 \begin{methoddesc}[socket]{settimeout}{value} |
|
23815
203d1412a7e8
Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents:
23730
diff
changeset
|
614 Set a timeout on blocking socket operations. The \var{value} argument |
|
203d1412a7e8
Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents:
23730
diff
changeset
|
615 can be a nonnegative float expressing seconds, or \code{None}. |
|
203d1412a7e8
Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents:
23730
diff
changeset
|
616 If a float is |
|
29665
d7626b80de95
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29560
diff
changeset
|
617 given, subsequent socket operations will raise an \exception{timeout} |
|
23728
5562a499fb7f
Clarify the interaction between blocking and timeouts. Explain that
Guido van Rossum <guido@python.org>
parents:
23720
diff
changeset
|
618 exception if the timeout period \var{value} has elapsed before the |
|
5562a499fb7f
Clarify the interaction between blocking and timeouts. Explain that
Guido van Rossum <guido@python.org>
parents:
23720
diff
changeset
|
619 operation has completed. Setting a timeout of \code{None} disables |
|
5562a499fb7f
Clarify the interaction between blocking and timeouts. Explain that
Guido van Rossum <guido@python.org>
parents:
23720
diff
changeset
|
620 timeouts on socket operations. |
|
29560
a296214d2ebb
SF #757229, fix libsocket.tex typo
Neal Norwitz <nnorwitz@gmail.com>
parents:
28844
diff
changeset
|
621 \code{s.settimeout(0.0)} is equivalent to \code{s.setblocking(0)}; |
|
23815
203d1412a7e8
Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents:
23730
diff
changeset
|
622 \code{s.settimeout(None)} is equivalent to \code{s.setblocking(1)}. |
|
23720
b062085c1ff2
Add version info, and fix another typo and wording spotted by /F. I think this is what he meant. :-)
Neal Norwitz <nnorwitz@gmail.com>
parents:
23719
diff
changeset
|
623 \versionadded{2.3} |
|
23717
77154cef29d1
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
21528
diff
changeset
|
624 \end{methoddesc} |
|
77154cef29d1
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
21528
diff
changeset
|
625 |
|
77154cef29d1
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
21528
diff
changeset
|
626 \begin{methoddesc}[socket]{gettimeout}{} |
|
23718
444954c5434c
Fix some markup errors and adjust wording slightly.
Fred Drake <fdrake@acm.org>
parents:
23717
diff
changeset
|
627 Returns the timeout in floating seconds associated with socket |
|
23815
203d1412a7e8
Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents:
23730
diff
changeset
|
628 operations, or \code{None} if no timeout is set. This reflects |
|
203d1412a7e8
Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents:
23730
diff
changeset
|
629 the last call to \method{setblocking()} or \method{settimeout()}. |
|
23720
b062085c1ff2
Add version info, and fix another typo and wording spotted by /F. I think this is what he meant. :-)
Neal Norwitz <nnorwitz@gmail.com>
parents:
23719
diff
changeset
|
630 \versionadded{2.3} |
|
23717
77154cef29d1
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
21528
diff
changeset
|
631 \end{methoddesc} |
|
77154cef29d1
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
21528
diff
changeset
|
632 |
|
23815
203d1412a7e8
Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents:
23730
diff
changeset
|
633 Some notes on socket blocking and timeouts: A socket object can be in |
|
29949
ad09687aaaa0
SF bug #774411: Typo in socket documentation
Raymond Hettinger <python@rcn.com>
parents:
29665
diff
changeset
|
634 one of three modes: blocking, non-blocking, or timeout. Sockets are |
|
23815
203d1412a7e8
Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents:
23730
diff
changeset
|
635 always created in blocking mode. In blocking mode, operations block |
|
203d1412a7e8
Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents:
23730
diff
changeset
|
636 until complete. In non-blocking mode, operations fail (with an error |
|
203d1412a7e8
Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents:
23730
diff
changeset
|
637 that is unfortunately system-dependent) if they cannot be completed |
|
203d1412a7e8
Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents:
23730
diff
changeset
|
638 immediately. In timeout mode, operations fail if they cannot be |
|
203d1412a7e8
Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents:
23730
diff
changeset
|
639 completed within the timeout specified for the socket. The |
|
203d1412a7e8
Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents:
23730
diff
changeset
|
640 \method{setblocking()} method is simply a shorthand for certain |
|
203d1412a7e8
Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents:
23730
diff
changeset
|
641 \method{settimeout()} calls. |
|
23717
77154cef29d1
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
21528
diff
changeset
|
642 |
|
23730
af8d40e4c377
Clarify the interaction between timeout/non-blocking mode, makefile
Guido van Rossum <guido@python.org>
parents:
23729
diff
changeset
|
643 Timeout mode internally sets the socket in non-blocking mode. The |
|
af8d40e4c377
Clarify the interaction between timeout/non-blocking mode, makefile
Guido van Rossum <guido@python.org>
parents:
23729
diff
changeset
|
644 blocking and timeout modes are shared between file descriptors and |
|
af8d40e4c377
Clarify the interaction between timeout/non-blocking mode, makefile
Guido van Rossum <guido@python.org>
parents:
23729
diff
changeset
|
645 socket objects that refer to the same network endpoint. A consequence |
|
af8d40e4c377
Clarify the interaction between timeout/non-blocking mode, makefile
Guido van Rossum <guido@python.org>
parents:
23729
diff
changeset
|
646 of this is that file objects returned by the \method{makefile()} |
|
af8d40e4c377
Clarify the interaction between timeout/non-blocking mode, makefile
Guido van Rossum <guido@python.org>
parents:
23729
diff
changeset
|
647 method should only be used when the socket is in blocking mode; in |
|
af8d40e4c377
Clarify the interaction between timeout/non-blocking mode, makefile
Guido van Rossum <guido@python.org>
parents:
23729
diff
changeset
|
648 timeout or non-blocking mode file operations that cannot be completed |
|
af8d40e4c377
Clarify the interaction between timeout/non-blocking mode, makefile
Guido van Rossum <guido@python.org>
parents:
23729
diff
changeset
|
649 immediately will fail. |
|
af8d40e4c377
Clarify the interaction between timeout/non-blocking mode, makefile
Guido van Rossum <guido@python.org>
parents:
23729
diff
changeset
|
650 |
|
31181
e5d97ab710a2
After hearing from someone who gave up on timeout sockets due to a
Guido van Rossum <guido@python.org>
parents:
31027
diff
changeset
|
651 Note that the \method{connect()} operation is subject to the timeout |
|
e5d97ab710a2
After hearing from someone who gave up on timeout sockets due to a
Guido van Rossum <guido@python.org>
parents:
31027
diff
changeset
|
652 setting, and in general it is recommended to call |
|
e5d97ab710a2
After hearing from someone who gave up on timeout sockets due to a
Guido van Rossum <guido@python.org>
parents:
31027
diff
changeset
|
653 \method{settimeout()} before calling \method{connect()}. |
|
e5d97ab710a2
After hearing from someone who gave up on timeout sockets due to a
Guido van Rossum <guido@python.org>
parents:
31027
diff
changeset
|
654 |
|
7823
0575d5a17218
Use {methoddesc} as appropriate.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
655 \begin{methoddesc}[socket]{setsockopt}{level, optname, value} |
|
13178
d37374552a15
Say "manual page", not "man page", when referring to the Unix manual.
Fred Drake <fdrake@acm.org>
parents:
12571
diff
changeset
|
656 Set the value of the given socket option (see the \UNIX{} manual page |
| 7632 | 657 \manpage{setsockopt}{2}). The needed symbolic constants are defined in |
|
28844
cd82253f20b7
- add availability statements for some of the new APIs
Fred Drake <fdrake@acm.org>
parents:
28837
diff
changeset
|
658 the \module{socket} module (\constant{SO_*} etc.). The value can be an |
|
2447
73499a667e78
changes refs to SO_* symbols
Guido van Rossum <guido@python.org>
parents:
2354
diff
changeset
|
659 integer or a string representing a buffer. In the latter case it is |
|
73499a667e78
changes refs to SO_* symbols
Guido van Rossum <guido@python.org>
parents:
2354
diff
changeset
|
660 up to the caller to ensure that the string contains the proper bits |
|
73499a667e78
changes refs to SO_* symbols
Guido van Rossum <guido@python.org>
parents:
2354
diff
changeset
|
661 (see the optional built-in module |
| 10655 | 662 \refmodule{struct}\refbimodindex{struct} for a way to encode C |
| 663 structures as strings). | |
|
7823
0575d5a17218
Use {methoddesc} as appropriate.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
664 \end{methoddesc} |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
665 |
|
7823
0575d5a17218
Use {methoddesc} as appropriate.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
666 \begin{methoddesc}[socket]{shutdown}{how} |
| 7632 | 667 Shut down one or both halves of the connection. If \var{how} is |
|
31027
bf038986cb8f
Patch #849595: Add socket.shutdown() constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
30048
diff
changeset
|
668 \constant{SHUT_RD}, further receives are disallowed. If \var{how} is \constant{SHUT_WR}, |
|
bf038986cb8f
Patch #849595: Add socket.shutdown() constants.
Martin v. Löwis <martin@v.loewis.de>
parents:
30048
diff
changeset
|
669 further sends are disallowed. If \var{how} is \constant{SHUT_RDWR}, further sends |
| 7632 | 670 and receives are disallowed. |
|
7823
0575d5a17218
Use {methoddesc} as appropriate.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
671 \end{methoddesc} |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
672 |
| 7632 | 673 Note that there are no methods \method{read()} or \method{write()}; |
| 674 use \method{recv()} and \method{send()} without \var{flags} argument | |
| 675 instead. | |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
676 |
|
13386
3f08bedc1c26
Clean up markup to be more like recommended practice; only small changes
Fred Drake <fdrake@acm.org>
parents:
13178
diff
changeset
|
677 |
|
20082
18df32f6cea1
Added documentation for the SSL interface, contributed by Gerhard Häring.
Fred Drake <fdrake@acm.org>
parents:
18995
diff
changeset
|
678 \subsection{SSL Objects \label{ssl-objects}} |
|
18df32f6cea1
Added documentation for the SSL interface, contributed by Gerhard Häring.
Fred Drake <fdrake@acm.org>
parents:
18995
diff
changeset
|
679 |
|
18df32f6cea1
Added documentation for the SSL interface, contributed by Gerhard Häring.
Fred Drake <fdrake@acm.org>
parents:
18995
diff
changeset
|
680 SSL objects have the following methods. |
|
18df32f6cea1
Added documentation for the SSL interface, contributed by Gerhard Häring.
Fred Drake <fdrake@acm.org>
parents:
18995
diff
changeset
|
681 |
|
18df32f6cea1
Added documentation for the SSL interface, contributed by Gerhard Häring.
Fred Drake <fdrake@acm.org>
parents:
18995
diff
changeset
|
682 \begin{methoddesc}{write}{s} |
|
18df32f6cea1
Added documentation for the SSL interface, contributed by Gerhard Häring.
Fred Drake <fdrake@acm.org>
parents:
18995
diff
changeset
|
683 Writes the string \var{s} to the on the object's SSL connection. |
|
18df32f6cea1
Added documentation for the SSL interface, contributed by Gerhard Häring.
Fred Drake <fdrake@acm.org>
parents:
18995
diff
changeset
|
684 The return value is the number of bytes written. |
|
18df32f6cea1
Added documentation for the SSL interface, contributed by Gerhard Häring.
Fred Drake <fdrake@acm.org>
parents:
18995
diff
changeset
|
685 \end{methoddesc} |
|
18df32f6cea1
Added documentation for the SSL interface, contributed by Gerhard Häring.
Fred Drake <fdrake@acm.org>
parents:
18995
diff
changeset
|
686 |
|
18df32f6cea1
Added documentation for the SSL interface, contributed by Gerhard Häring.
Fred Drake <fdrake@acm.org>
parents:
18995
diff
changeset
|
687 \begin{methoddesc}{read}{\optional{n}} |
|
18df32f6cea1
Added documentation for the SSL interface, contributed by Gerhard Häring.
Fred Drake <fdrake@acm.org>
parents:
18995
diff
changeset
|
688 If \var{n} is provided, read \var{n} bytes from the SSL connection, otherwise |
|
18df32f6cea1
Added documentation for the SSL interface, contributed by Gerhard Häring.
Fred Drake <fdrake@acm.org>
parents:
18995
diff
changeset
|
689 read until EOF. The return value is a string of the bytes read. |
|
18df32f6cea1
Added documentation for the SSL interface, contributed by Gerhard Häring.
Fred Drake <fdrake@acm.org>
parents:
18995
diff
changeset
|
690 \end{methoddesc} |
|
18df32f6cea1
Added documentation for the SSL interface, contributed by Gerhard Häring.
Fred Drake <fdrake@acm.org>
parents:
18995
diff
changeset
|
691 |
|
13386
3f08bedc1c26
Clean up markup to be more like recommended practice; only small changes
Fred Drake <fdrake@acm.org>
parents:
13178
diff
changeset
|
692 \subsection{Example \label{socket-example}} |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
693 |
|
18995
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
694 Here are four minimal example programs using the TCP/IP protocol:\ a |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
695 server that echoes all data that it receives back (servicing only one |
|
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
696 client), and a client using it. Note that a server must perform the |
| 7632 | 697 sequence \function{socket()}, \method{bind()}, \method{listen()}, |
| 698 \method{accept()} (possibly repeating the \method{accept()} to service | |
| 699 more than one client), while a client only needs the sequence | |
| 700 \function{socket()}, \method{connect()}. Also note that the server | |
| 701 does not \method{send()}/\method{recv()} on the | |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
702 socket it is listening on but on the new socket returned by |
| 7632 | 703 \method{accept()}. |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
704 |
|
18995
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
705 The first two examples support IPv4 only. |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
706 |
|
7277
bf4e790bd61a
Remove all \bcode / \ecode cruft; this is no longer needed. See previous
Fred Drake <fdrake@acm.org>
parents:
7200
diff
changeset
|
707 \begin{verbatim} |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
708 # Echo server program |
|
15146
5cf0a02a574b
Revise the examples not to use the "from socket import *", and adjust
Fred Drake <fdrake@acm.org>
parents:
14437
diff
changeset
|
709 import socket |
|
5cf0a02a574b
Revise the examples not to use the "from socket import *", and adjust
Fred Drake <fdrake@acm.org>
parents:
14437
diff
changeset
|
710 |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
711 HOST = '' # Symbolic name meaning the local host |
|
15146
5cf0a02a574b
Revise the examples not to use the "from socket import *", and adjust
Fred Drake <fdrake@acm.org>
parents:
14437
diff
changeset
|
712 PORT = 50007 # Arbitrary non-privileged port |
|
5cf0a02a574b
Revise the examples not to use the "from socket import *", and adjust
Fred Drake <fdrake@acm.org>
parents:
14437
diff
changeset
|
713 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
|
12571
8bcd14313c11
Someone found the examples of poor practice on socket addresses!
Fred Drake <fdrake@acm.org>
parents:
12230
diff
changeset
|
714 s.bind((HOST, PORT)) |
|
1567
dddcba2038bc
adapt to min value of 1 for listen() backlog argument
Guido van Rossum <guido@python.org>
parents:
1483
diff
changeset
|
715 s.listen(1) |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
716 conn, addr = s.accept() |
|
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
717 print 'Connected by', addr |
|
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
718 while 1: |
|
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
719 data = conn.recv(1024) |
|
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
720 if not data: break |
|
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
721 conn.send(data) |
|
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
722 conn.close() |
|
7277
bf4e790bd61a
Remove all \bcode / \ecode cruft; this is no longer needed. See previous
Fred Drake <fdrake@acm.org>
parents:
7200
diff
changeset
|
723 \end{verbatim} |
| 7632 | 724 |
|
7277
bf4e790bd61a
Remove all \bcode / \ecode cruft; this is no longer needed. See previous
Fred Drake <fdrake@acm.org>
parents:
7200
diff
changeset
|
725 \begin{verbatim} |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
726 # Echo client program |
|
15146
5cf0a02a574b
Revise the examples not to use the "from socket import *", and adjust
Fred Drake <fdrake@acm.org>
parents:
14437
diff
changeset
|
727 import socket |
|
5cf0a02a574b
Revise the examples not to use the "from socket import *", and adjust
Fred Drake <fdrake@acm.org>
parents:
14437
diff
changeset
|
728 |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
729 HOST = 'daring.cwi.nl' # The remote host |
|
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
730 PORT = 50007 # The same port as used by the server |
|
15146
5cf0a02a574b
Revise the examples not to use the "from socket import *", and adjust
Fred Drake <fdrake@acm.org>
parents:
14437
diff
changeset
|
731 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
|
12571
8bcd14313c11
Someone found the examples of poor practice on socket addresses!
Fred Drake <fdrake@acm.org>
parents:
12230
diff
changeset
|
732 s.connect((HOST, PORT)) |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
733 s.send('Hello, world') |
|
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
734 data = s.recv(1024) |
|
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
735 s.close() |
|
32231
525abc66bcc2
avoid backticks in examples; use repr() instead
Fred Drake <fdrake@acm.org>
parents:
31976
diff
changeset
|
736 print 'Received', repr(data) |
|
7277
bf4e790bd61a
Remove all \bcode / \ecode cruft; this is no longer needed. See previous
Fred Drake <fdrake@acm.org>
parents:
7200
diff
changeset
|
737 \end{verbatim} |
|
18995
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
738 |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
739 The next two examples are identical to the above two, but support both |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
740 IPv4 and IPv6. |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
741 The server side will listen to the first address family available |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
742 (it should listen to both instead). |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
743 On most of IPv6-ready systems, IPv6 will take precedence |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
744 and the server may not accept IPv4 traffic. |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
745 The client side will try to connect to the all addresses returned as a result |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
746 of the name resolution, and sends traffic to the first one connected |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
747 successfully. |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
748 |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
749 \begin{verbatim} |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
750 # Echo server program |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
751 import socket |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
752 import sys |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
753 |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
754 HOST = '' # Symbolic name meaning the local host |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
755 PORT = 50007 # Arbitrary non-privileged port |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
756 s = None |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
757 for res in socket.getaddrinfo(HOST, PORT, socket.AF_UNSPEC, socket.SOCK_STREAM, 0, socket.AI_PASSIVE): |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
758 af, socktype, proto, canonname, sa = res |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
759 try: |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
760 s = socket.socket(af, socktype, proto) |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
761 except socket.error, msg: |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
762 s = None |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
763 continue |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
764 try: |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
765 s.bind(sa) |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
766 s.listen(1) |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
767 except socket.error, msg: |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
768 s.close() |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
769 s = None |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
770 continue |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
771 break |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
772 if s is None: |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
773 print 'could not open socket' |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
774 sys.exit(1) |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
775 conn, addr = s.accept() |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
776 print 'Connected by', addr |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
777 while 1: |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
778 data = conn.recv(1024) |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
779 if not data: break |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
780 conn.send(data) |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
781 conn.close() |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
782 \end{verbatim} |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
783 |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
784 \begin{verbatim} |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
785 # Echo client program |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
786 import socket |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
787 import sys |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
788 |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
789 HOST = 'daring.cwi.nl' # The remote host |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
790 PORT = 50007 # The same port as used by the server |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
791 s = None |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
792 for res in socket.getaddrinfo(HOST, PORT, socket.AF_UNSPEC, socket.SOCK_STREAM): |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
793 af, socktype, proto, canonname, sa = res |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
794 try: |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
795 s = socket.socket(af, socktype, proto) |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
796 except socket.error, msg: |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
797 s = None |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
798 continue |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
799 try: |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
800 s.connect(sa) |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
801 except socket.error, msg: |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
802 s.close() |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
803 s = None |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
804 continue |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
805 break |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
806 if s is None: |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
807 print 'could not open socket' |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
808 sys.exit(1) |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
809 s.send('Hello, world') |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
810 data = s.recv(1024) |
|
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
811 s.close() |
|
32231
525abc66bcc2
avoid backticks in examples; use repr() instead
Fred Drake <fdrake@acm.org>
parents:
31976
diff
changeset
|
812 print 'Received', repr(data) |
|
18995
805090ce328a
Document IPv6 changes. Contributed by itojun.
Martin v. Löwis <martin@v.loewis.de>
parents:
15800
diff
changeset
|
813 \end{verbatim} |
