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

  • 10 Replies
  • 639 Views
*

Offline tha

  • *****
  • 4992
    • View Profile
Re: STM32 ETHERNET #7 UDP Server using LWIP NETCONN (RTOS)
« Reply #8 on: February 24, 2023, 09:44:52 am »
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.

*

Offline tha

  • *****
  • 4992
    • View Profile
Re: STM32 ETHERNET #7 UDP Server using LWIP NETCONN (RTOS)
« Reply #9 on: February 24, 2023, 09:51:19 am »
                                                                                               Result

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


*

Offline tha

  • *****
  • 4992
    • View Profile
Re: STM32 ETHERNET #7 UDP Server using LWIP NETCONN (RTOS)
« Reply #10 on: February 24, 2023, 09:52:55 am »
<a href="https://www.youtube.com/v/6olMulM5SCg" target="_blank" class="new_win">https://www.youtube.com/v/6olMulM5SCg</a>