STM32 ETHERNET #7 UDP Server using LWIP NETCONN (RTOS)

Started by tha, February 22, 2023, 09:47:12 AM

Previous topic - Next topic

tha

The udp_thread:




•   ที่นี่ก่อนอื่นเราจะสร้าง a new netconn connection. NETCONN_UDP argument จะสร้าง a UDP connection.
•   ถัดไปเราจะผูก the connection เข้ากับ available IP address ใดๆและ the Port 7. นี้จะทำหน้าที่เป็น the IP and port ของ the
     server.
•   จากนั้นเราจะรับ the data จาก the client. The netconn_recv function จะรอจนกว่า the data ถุกรับ.
•   หลังจากการรับ the data, เราจะแยก the address, port และ message ที่ส่งโดย the client.
•   เนื่องจากนี่เป็นเพียงบทแนะนำการทดสอบเท่านั้น เราจะแก้ไข message นี้, และจัดเก็บมันไว้ใน smgs เพื่อให้เราสามารถส่งมันกลับไปยัง
     client.
•   ถัดไปเราต้องบันทึก the message ใน the pbuf เพื่อส่งมันกลับไปยัง the client.
•   ในการทำเช่นนั้น ก่อนอื่นเราต้องจัดสรร the RAM สำหรับ the pbuf.
•   จากนั้น pbuf_take จะถูกใช้เพื่อก๊อปปี้ the modified message ลงใน the pbuf.
•   ถัดไปเราจะอ้างอิง the netbuf->pbuf กับ pbuf ของเรา. นี่เป็นเพราะใน Netconn, เราสามารถส่งได้เฉพาะ the nebuf, ดังนั้นเราต้อง
     อัปเดต the reference ของ the netbuf->pbuf.
•   ถัดไปเราจะเชื่อมต่อกับ the client โดยใช้ the address, และ port ที่เราเก็บไว้ก่อนหน้านี้.
•   สุดท้ายส่ง the netbuf ไปยัง the client, ซึ่งบรรจุ the updated message.

tha

                                                                                               Result

ข้างล่างคือ the screenshot ของ the data ที่ส่งโดย the client และ the response ที่ส่งโดย the server.