@@ -68,7 +68,16 @@ Functions
68
68
69
69
.. function :: socket(af=AF_INET, type=SOCK_STREAM, proto=IPPROTO_TCP)
70
70
71
- Create a new socket using the given address family, socket type and protocol number.
71
+ Create a new socket using the given address family, socket type and
72
+ protocol number. Note that specifying *proto * in most cases is not
73
+ required (and not recommended, as some MicroPython ports may omit
74
+ ``IPPROTO_* `` constants). Instead, *type * argument will select needed
75
+ protocol automatically::
76
+
77
+ # Create STREAM TCP socket
78
+ socket(AF_INET, SOCK_STREAM)
79
+ # Create DGRAM UDP socket
80
+ socket(AF_INET, SOCK_DGRAM)
72
81
73
82
.. function :: getaddrinfo(host, port)
74
83
@@ -80,8 +89,8 @@ Functions
80
89
81
90
The following example shows how to connect to a given url::
82
91
83
- s = socket .socket()
84
- s.connect(socket .getaddrinfo('www.micropython.org', 80)[0][-1])
92
+ s = usocket .socket()
93
+ s.connect(usocket .getaddrinfo('www.micropython.org', 80)[0][-1])
85
94
86
95
.. admonition :: Difference to CPython
87
96
:class: attention
@@ -102,7 +111,7 @@ Constants
102
111
.. data :: AF_INET
103
112
AF_INET6
104
113
105
- Address family types. Availability depends on a particular board .
114
+ Address family types. Availability depends on a particular ` MicroPython port ` .
106
115
107
116
.. data :: SOCK_STREAM
108
117
SOCK_DGRAM
@@ -112,7 +121,11 @@ Constants
112
121
.. data :: IPPROTO_UDP
113
122
IPPROTO_TCP
114
123
115
- IP protocol numbers.
124
+ IP protocol numbers. Availability depends on a particular `MicroPython port `.
125
+ Note that you don't need to specify these in a call to `usocket.socket() `,
126
+ because `SOCK_STREAM ` socket type automatically selects `IPPROTO_TCP `, and
127
+ `SOCK_DGRAM ` - `IPPROTO_UDP `. Thus, the only real use of these constants
128
+ is as an argument to `setsockopt() `.
116
129
117
130
.. data :: usocket.SOL_*
118
131
@@ -281,7 +294,7 @@ Methods
281
294
282
295
Return value: number of bytes written.
283
296
284
- .. exception :: socket .error
297
+ .. exception :: usocket .error
285
298
286
299
MicroPython does NOT have this exception.
287
300
0 commit comments