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 or UDP communication sample code

Hi John,

Hope you are doing good.
I have a LWIP driver code in which the webserver is implemented.
But I need a simple TCP/IP or UDP communication sample code.


Thanks in Advance.

Regards,
Immanuel
  • Hello Immanuel,

    This is example for UDP. Just as a reference

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

    _enable_IRQ();
    EMAC_LwIP_Main(emacAddress);
    IP4_ADDR(&Src, 192, 168, 0, 12);
    IP4_ADDR(&Dst, 192, 168, 0, 10);
    IP4_ADDR(&netmask, 255, 255, 255, 0);
    IP4_ADDR(&gw, 192, 168, 0, 1);
    pcb=udp_new();
    error=udp_bind(pcb,&Src,PORT_NO);
    error=udp_connect(pcb,&Dst,PORT_NO);
    length = 5;
    Tx=pbuf_alloc(PBUF_TRANSPORT,length, PBUF_RAM);
    Tx->next=0;
    Tx->len=Tx->tot_len=length;
    memcpy (Tx->payload, msg, Tx->len);
    udp_sendto(pcb, Tx, &Dst, PORT_NO);
    pbuf_free(Tx);