netconn_send() — Send data on UDP connection


err_t netconn_send(struct netconn *conn, struct netbuf *buf);


Send the data in the netbuf buf on the UDP connection conn. The data in the netbuf should not be too large if IP fragmentation support is disabled. If IP fragmentation support is disabled, the data should not be larger than the maximum transmission unit (MTU) of the outgoing network interface, less the space required for link layer, IP and UDP headers. No checking is necessarily made of whether the data is sufficiently small and sending very large netbufs might give undefined results.


Example 164.8. This example demonstrates basic usage of the netconn_send() function [*]

This example shows how to send some UDP data to UDP port 7000 on a remote host with IP address

    struct netconn *conn;
    struct netbuf *buf;
    struct ip_addr addr;
    char *data;
    char text[] = "A static text";
    int i;

    /* create a new connection */
    conn = netconn_new(NETCONN_UDP);

    /* set up the IP address of the remote host */
    addr.addr = htonl(0x0a000001);

    /* connect the connection to the remote host */
    netconn_connect(conn, addr, 7000);

    /* create a new netbuf */
    buf = netbuf_new();
    data = netbuf_alloc(buf, 10);

    /* create some arbitrary data */
    for(i = 0; i < 10; i++)
        data[i] = i;

    /* send the arbitrary data */
    netconn_send(conn, buf);

    /* reference the text into the netbuf */
    netbuf_ref(buf, text, sizeof(text));

    /* send the text */
    netconn_send(conn, buf);

    /* deallocate connection and netbuf */

[*] This is only an example for illustrative purposes, and a complete version should perform comprehensive error checking.