@@ -14,34 +14,34 @@ for comparison.
1414 :class: attention
1515
1616 CPython used to have a ``socket.error `` exception which is now deprecated,
17- and is an alias of OSError. In MicroPython, use OSError directly.
17+ and is an alias of ` OSError ` . In MicroPython, use ` OSError ` directly.
1818
1919.. admonition :: Difference to CPython
2020 :class: attention
2121
2222 For efficiency and consistency, socket objects in MicroPython implement a stream
2323 (file-like) interface directly. In CPython, you need to convert a socket to
24- a file-like object using `` makefile() ` ` method. This method is still supported
24+ a file-like object using `makefile() ` method. This method is still supported
2525 by MicroPython (but is a no-op), so where compatibility with CPython matters,
2626 be sure to use it.
2727
2828Socket address format(s)
2929------------------------
3030
3131The functions below which expect a network address, accept it in the format of
32- ` (ipv4_address, port) ` , where ` ipv4_address ` is a string with dot-notation numeric
32+ * (ipv4_address, port) * , where * ipv4_address * is a string with dot-notation numeric
3333IPv4 address, e.g. ``"8.8.8.8" ``, and port is integer port number in the range
34- 1-65535. Note the domain names are not accepted as ` ipv4_address ` , they should be
35- resolved first using `` socket .getaddrinfo()` `.
34+ 1-65535. Note the domain names are not accepted as * ipv4_address * , they should be
35+ resolved first using `usocket .getaddrinfo() `.
3636
3737Functions
3838---------
3939
40- .. function :: socket.socket(socket. AF_INET, socket. SOCK_STREAM, socket. IPPROTO_TCP)
40+ .. function :: socket(af= AF_INET, type= SOCK_STREAM, proto= IPPROTO_TCP)
4141
4242 Create a new socket using the given address family, socket type and protocol number.
4343
44- .. function :: socket. getaddrinfo(host, port)
44+ .. function :: getaddrinfo(host, port)
4545
4646 Translate the host/port argument into a sequence of 5-tuples that contain all the
4747 necessary arguments for creating a socket connected to that service. The list of
@@ -57,11 +57,11 @@ Functions
5757 .. admonition :: Difference to CPython
5858 :class: attention
5959
60- CPython raises a ``socket.gaierror `` exception (OSError subclass) in case
60+ CPython raises a ``socket.gaierror `` exception (` OSError ` subclass) in case
6161 of error in this function. MicroPython doesn't have ``socket.gaierror ``
62- and raises OSError directly. Note that error numbers of `` getaddrinfo() ` `
62+ and raises OSError directly. Note that error numbers of `getaddrinfo() `
6363 form a separate namespace and may not match error numbers from
64- `` uerrno `` module. To distinguish `` getaddrinfo() ` ` errors, they are
64+ `uerrno ` module. To distinguish `getaddrinfo() ` errors, they are
6565 represented by negative numbers, whereas standard system errors are
6666 positive numbers (error numbers are accessible using ``e.args[0] `` property
6767 from an exception object). The use of negative values is a provisional
@@ -70,32 +70,34 @@ Functions
7070Constants
7171---------
7272
73- .. data :: socket. AF_INET
74- socket. AF_INET6
73+ .. data :: AF_INET
74+ AF_INET6
7575
7676 Address family types. Availability depends on a particular board.
7777
78- .. data :: socket. SOCK_STREAM
79- socket. SOCK_DGRAM
78+ .. data :: SOCK_STREAM
79+ SOCK_DGRAM
8080
8181 Socket types.
8282
83- .. data :: socket. IPPROTO_UDP
84- socket. IPPROTO_TCP
83+ .. data :: IPPROTO_UDP
84+ IPPROTO_TCP
8585
8686 IP protocol numbers.
8787
88- .. data :: socket .SOL_*
88+ .. data :: usocket .SOL_*
8989
90- Socket option levels (an argument to ``setsockopt() ``). The exact inventory depends on a board.
90+ Socket option levels (an argument to `setsockopt() `). The exact
91+ inventory depends on a MicroPython port.
9192
92- .. data :: socket .SO_*
93+ .. data :: usocket .SO_*
9394
94- Socket options (an argument to ``setsockopt() ``). The exact inventory depends on a board.
95+ Socket options (an argument to `setsockopt() `). The exact
96+ inventory depends on a MicroPython port.
9597
9698Constants specific to WiPy:
9799
98- .. data :: socket. IPPROTO_SEC
100+ .. data :: IPPROTO_SEC
99101
100102 Special protocol value to create SSL-compatible socket.
101103
@@ -105,21 +107,22 @@ class socket
105107Methods
106108-------
107109
108- .. method :: socket.close
110+ .. method :: socket.close()
109111
110- Mark the socket closed. Once that happens, all future operations on the socket
111- object will fail. The remote end will receive no more data (after queued data is flushed).
112+ Mark the socket closed and release all resources. Once that happens, all future operations
113+ on the socket object will fail. The remote end will receive EOF indication if
114+ supported by protocol.
112115
113116 Sockets are automatically closed when they are garbage-collected, but it is recommended
114- to close() them explicitly, or to use a with statement around them.
117+ to ` close() ` them explicitly as soon you finished working with them.
115118
116119.. method :: socket.bind(address)
117120
118- Bind the socket to address. The socket must not already be bound.
121+ Bind the socket to * address * . The socket must not already be bound.
119122
120123.. method :: socket.listen([backlog])
121124
122- Enable a server to accept connections. If backlog is specified, it must be at least 0
125+ Enable a server to accept connections. If * backlog * is specified, it must be at least 0
123126 (if it's lower, it will be set to 0); and specifies the number of unaccepted connections
124127 that the system will allow before refusing new connections. If not specified, a default
125128 reasonable value is chosen.
@@ -133,7 +136,7 @@ Methods
133136
134137.. method :: socket.connect(address)
135138
136- Connect to a remote socket at address.
139+ Connect to a remote socket at * address * .
137140
138141.. method :: socket.send(bytes)
139142
@@ -144,11 +147,11 @@ Methods
144147.. method :: socket.sendall(bytes)
145148
146149 Send all data to the socket. The socket must be connected to a remote socket.
147- Unlike `` send() ` `, this method will try to send all of data, by sending data
150+ Unlike `send() `, this method will try to send all of data, by sending data
148151 chunk by chunk consecutively.
149152
150153 The behavior of this method on non-blocking sockets is undefined. Due to this,
151- on MicroPython, it's recommended to use `` write() ` ` method instead, which
154+ on MicroPython, it's recommended to use `write() ` method instead, which
152155 has the same "no short writes" policy for blocking sockets, and will return
153156 number of bytes sent on non-blocking sockets.
154157
@@ -160,33 +163,33 @@ Methods
160163.. method :: socket.sendto(bytes, address)
161164
162165 Send data to the socket. The socket should not be connected to a remote socket, since the
163- destination socket is specified by ` address ` .
166+ destination socket is specified by * address * .
164167
165168.. method :: socket.recvfrom(bufsize)
166169
167- Receive data from the socket. The return value is a pair (bytes, address) where bytes is a
168- bytes object representing the data received and address is the address of the socket sending
170+ Receive data from the socket. The return value is a pair * (bytes, address) * where * bytes * is a
171+ bytes object representing the data received and * address * is the address of the socket sending
169172 the data.
170173
171174.. method :: socket.setsockopt(level, optname, value)
172175
173176 Set the value of the given socket option. The needed symbolic constants are defined in the
174- socket module (SO_* etc.). The value can be an integer or a bytes-like object representing
177+ socket module (SO_* etc.). The * value * can be an integer or a bytes-like object representing
175178 a buffer.
176179
177180.. method :: socket.settimeout(value)
178181
179182 Set a timeout on blocking socket operations. The value argument can be a nonnegative floating
180183 point number expressing seconds, or None. If a non-zero value is given, subsequent socket operations
181- will raise an `` OSError ` ` exception if the timeout period value has elapsed before the operation has
184+ will raise an `OSError ` exception if the timeout period value has elapsed before the operation has
182185 completed. If zero is given, the socket is put in non-blocking mode. If None is given, the socket
183186 is put in blocking mode.
184187
185188 .. admonition :: Difference to CPython
186189 :class: attention
187190
188191 CPython raises a ``socket.timeout `` exception in case of timeout,
189- which is an `` OSError ` ` subclass. MicroPython raises an OSError directly
192+ which is an `OSError ` subclass. MicroPython raises an OSError directly
190193 instead. If you use ``except OSError: `` to catch the exception,
191194 your code will work both in MicroPython and CPython.
192195
@@ -195,7 +198,7 @@ Methods
195198 Set blocking or non-blocking mode of the socket: if flag is false, the socket is set to non-blocking,
196199 else to blocking mode.
197200
198- This method is a shorthand for certain `` settimeout() ` ` calls:
201+ This method is a shorthand for certain `settimeout() ` calls:
199202
200203 * ``sock.setblocking(True) `` is equivalent to ``sock.settimeout(None) ``
201204 * ``sock.setblocking(False) `` is equivalent to ``sock.settimeout(0) ``
@@ -204,12 +207,12 @@ Methods
204207
205208 Return a file object associated with the socket. The exact returned type depends on the arguments
206209 given to makefile(). The support is limited to binary modes only ('rb', 'wb', and 'rwb').
207- CPython's arguments: `` encoding ``, `` errors `` and `` newline `` are not supported.
210+ CPython's arguments: * encoding *, * errors * and * newline * are not supported.
208211
209212 .. admonition :: Difference to CPython
210213 :class: attention
211214
212- As MicroPython doesn't support buffered streams, values of `` buffering ``
215+ As MicroPython doesn't support buffered streams, values of * buffering *
213216 parameter is ignored and treated as if it was 0 (unbuffered).
214217
215218 .. admonition :: Difference to CPython
@@ -220,19 +223,19 @@ Methods
220223
221224.. method :: socket.read([size])
222225
223- Read up to size bytes from the socket. Return a bytes object. If `` size `` is not given, it
224- reads all data available from the socket until `` EOF `` ; as such the method will not return until
226+ Read up to size bytes from the socket. Return a bytes object. If * size * is not given, it
227+ reads all data available from the socket until EOF; as such the method will not return until
225228 the socket is closed. This function tries to read as much data as
226229 requested (no "short reads"). This may be not possible with
227230 non-blocking socket though, and then less data will be returned.
228231
229232.. method :: socket.readinto(buf[, nbytes])
230233
231- Read bytes into the `` buf `` . If `` nbytes `` is specified then read at most
232- that many bytes. Otherwise, read at most `` len(buf) `` bytes. Just as
233- `` read() ` `, this method follows "no short reads" policy.
234+ Read bytes into the * buf * . If * nbytes * is specified then read at most
235+ that many bytes. Otherwise, read at most * len(buf) * bytes. Just as
236+ `read() `, this method follows "no short reads" policy.
234237
235- Return value: number of bytes read and stored into `` buf `` .
238+ Return value: number of bytes read and stored into * buf * .
236239
237240.. method :: socket.readline()
238241
@@ -245,6 +248,6 @@ Methods
245248 Write the buffer of bytes to the socket. This function will try to
246249 write all data to a socket (no "short writes"). This may be not possible
247250 with a non-blocking socket though, and returned value will be less than
248- the length of `` buf `` .
251+ the length of * buf * .
249252
250253 Return value: number of bytes written.
0 commit comments