This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[参考译文] TCP/IP 或 UDP 通信示例代码

Guru**** 2481465 points


请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/arm-based-microcontrollers-group/arm-based-microcontrollers/f/arm-based-microcontrollers-forum/705220/tcp-ip-or-udp-communication-sample-code

尊敬的 John:

希望你们做得好。
我有一个 LWIP 驱动程序代码,用于实现 Web 服务器。
但我需要一个简单的 TCP/IP 或 UDP 通信示例代码。


提前感谢。

此致、
伊曼纽尔
  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
    伊曼纽尔、您好、

    这是 UDP 的示例。 仅供参考

    struct pbuf *Tx;
    uint16_t length=0;
    字符 msg[5];

    _enable_IRQ ();
    EMAC_LwIP_Main (emacAddress);
    IP4_ADDR (&src、192、168、0、12);
    IP4_ADDR (&dst、192、168、0、10);
    IP4_ADDR (网络掩码、255、255、255、0);
    IP4_ADDR (&GW、192、168、0、1);
    pc=udp_new();
    error=udp_bind (PCB、&src、port_no);
    error=udp_connect (PCB、&D、port_no);
    长度= 5;
    tx=pbuf_alloc (PBUF_transport、length、PBUF_RAM);
    Tx->NEX=0;
    tx->len=tx->t_tlen=length;
    memcpy (Tx->PAYLOAD, msg, Tx->len);
    udp_sendto (PCB、Tx、&dst、port_no);
    pbuf_free (Tx);