1- UDP Client
2- ==========
1+ EasyUDPClient
2+ =============
33
4- .. include :: ../refs/software.udp.client.ref
4+ .. include :: ../refs/software.easysocket.udp.client.ref
5+
6+ EasyUDPClient provides a simple way to create UDP clients in an event-driven manner.
57
68UiFlow2 Example
79---------------
810
911simple client
1012^^^^^^^^^^^^^
1113
12- Open the |cores3_udp_client_example .m5f2 | project in UiFlow2.
14+ Open the |udp_client_core2_example .m5f2 | project in UiFlow2.
1315
14- This example creates a UDP client that sends data to a server.
16+ This example creates a UDP client that connects to a server and sends data .
1517
1618UiFlow2 Code Block:
1719
18- |cores3_udp_client_example .png |
20+ |udp_client_core2_example .png |
1921
2022Example output:
2123
@@ -24,14 +26,14 @@ Example output:
2426MicroPython Example
2527-------------------
2628
27- sample client
29+ simple client
2830^^^^^^^^^^^^^
2931
30- This example creates a UDP client that sends data to a server.
32+ This example creates a UDP client that connects to a server and sends data .
3133
3234MicroPython Code Block:
3335
34- .. literalinclude :: ../../../examples/software/udp/cores3_udp_client_example .py
36+ .. literalinclude :: ../../../examples/software/easysocket/udp_client/udp_client_core2_example .py
3537 :language: python
3638 :linenos:
3739
@@ -43,152 +45,5 @@ Example output:
4345**API **
4446-------
4547
46- .. method :: socket.socket()
47- socket.connect(address)
48- :no-index:
49-
50- Create a socket object and connect to the server.
51-
52- :param tuple address: A tuple containing the server IP address and port number.
53- :return: A socket object.
54- :rtype: socket.socket
55-
56- UiFlow2 Code Block:
57-
58- |init.png |
59-
60- MicroPython Code Block:
61-
62- .. code-block :: python
63-
64- import socket
65-
66- udpc = socket.socket(socket.AF_INET , socket.SOCK_DGRAM )
67- udpc.connect((' 192.168.8.236' , 8000 ))
68-
69-
70- .. method :: socket.close()
71- :no-index:
72-
73- Close the socket connection.
74-
75- UiFlow2 Code Block:
76-
77- |close.png |
78-
79- MicroPython Code Block:
80-
81- .. code-block :: python
82-
83- udpc.close()
84-
85-
86- .. method :: socket.recv(bufsize)
87- :no-index:
88-
89- Receive data from the socket.
90-
91- :param int bufsize: The maximum amount of data to be received at once.
92- :return: The received data.
93- :rtype: bytes
94-
95- UiFlow2 Code Block:
96-
97- |recv.png |
98-
99- MicroPython Code Block:
100-
101- .. code-block :: python
102-
103- data = udpc.recv(1024 )
104- print (data)
105-
106-
107- .. method :: socket.read()
108- :no-index:
109-
110- Read data from the socket.
111-
112- :return: The received data.
113- :rtype: bytes
114-
115- UiFlow2 Code Block:
116-
117- |read.png |
118-
119- MicroPython Code Block:
120-
121- .. code-block :: python
122-
123- data = udpc.read()
124- print (data)
125-
126-
127- .. method :: socket.send(data)
128- :no-index:
129-
130- Send data to the socket. The socket must be connected to a remote socket.
131-
132- :param data: The data to be sent.
133- :type data: bytes | str
134- :return: The number of bytes sent.
135- :rtype: int
136-
137- UiFlow2 Code Block:
138-
139- |send.png |
140-
141- MicroPython Code Block:
142-
143- .. code-block :: python
144-
145- udpc.send(b ' Hello, World!' )
146- udpc.send(' Hello, World!' )
147-
148-
149- .. method :: socket.write(data)
150- :no-index:
151-
152- Write the buffer of bytes to the socket. This function will try to write all
153- data to a socket (no “short writes”). This may be not possible with a
154- non-blocking socket though, and returned value will be less than the length
155- of buf.
156-
157- :param data: The data to be sent.
158- :type data: bytes | str
159- :return: The number of bytes sent.
160- :rtype: int
161-
162- UiFlow2 Code Block:
163-
164- |write.png |
165-
166- MicroPython Code Block:
167-
168- .. code-block :: python
169-
170- udpc.write(b ' Hello, World!' )
171- udpc.write(' Hello, World!' )
172-
173-
174- .. method :: socket.setsockopt(level, optname, value)
175- :no-index:
176-
177- Set the value of the given socket option. The needed symbolic constants are
178- defined in the socket module (SO_* etc.). The value can be an integer or a
179- bytes-like object representing a buffer.
180-
181- :param int level: The level at which the option is defined.
182- :param int optname: The name of the option to set.
183- :param value: The value to set for the option.
184-
185- UiFlow2 Code Block:
186-
187- |setsockopt.png |
188-
189- MicroPython Code Block:
190-
191- .. code-block :: python
192-
193- udpc.setsockopt(socket.SOL_SOCKET , socket.SO_REUSEADDR , 0 )
194- udpc.setsockopt(socket.SOL_SOCKET , socket.SO_REUSEADDR , 1 )
48+ .. autoclass :: software.easysocket.udp_client.EasyUDPClient
49+ :members:
0 commit comments