Netconn API

Netconn API is addon on top of existing connection module and allows sending and receiving data with sequential API calls, similar to POSIX socket API.

It can operate in client or server mode and uses operating system features, such as message queues and semaphore to link non-blocking callback API for connections with sequential API for application thread.

Note

Connection API does not directly allow receiving data with sequential and linear code execution. All is based on connection event system. Netconn adds this functionality as it is implemented on top of regular connection API.

Warning

Netconn API are designed to be called from application threads ONLY. It is not allowed to call any of netconn API functions from within interrupt or callback event functions.

Netconn client

Netconn API client block diagram

Netconn API client block diagram

Above block diagram shows basic architecture of netconn client application. There is always one application thread (in green) which calls netconn API functions to interact with connection API in synchronous mode.

Every netconn connection uses dedicated structure to handle message queue for data received packet buffers. Each time new packet is received (red block, data received event), reference to it is written to message queue of netconn structure, while application thread reads new entries from the same queue to get packets.

Netconn client example
  1/*
  2 * Netconn client demonstrates how to connect as a client to server
  3 * using sequential API from separate thread.
  4 * 
  5 * it does not use callbacks to obtain connection status.
  6 * 
  7 * Demo connects to NETCONN_HOST at NETCONN_PORT and sends GET request header,
  8 * then waits for respond and expects server to close the connection accordingly.
  9 */
 10#include "netconn_client.h"
 11#include "lwesp/lwesp_netconn.h"
 12#include "lwesp/lwesp.h"
 13
 14/**
 15 * \brief           Host and port settings
 16 */
 17#define NETCONN_HOST "example.com"
 18#define NETCONN_PORT 80
 19
 20/**
 21 * \brief           Request header to send on successful connection
 22 */
 23static const char request_header[] = ""
 24                                     "GET / HTTP/1.1\r\n"
 25                                     "Host: " NETCONN_HOST "\r\n"
 26                                     "Connection: close\r\n"
 27                                     "\r\n";
 28
 29/**
 30 * \brief           Netconn client thread implementation
 31 * \param[in]       arg: User argument
 32 */
 33void
 34netconn_client_thread(void const* arg) {
 35    lwespr_t res;
 36    lwesp_pbuf_p pbuf;
 37    lwesp_netconn_p client;
 38    lwesp_sys_sem_t* sem = (void*)arg;
 39
 40    /* Make sure we are connected to access point first */
 41    while (!lwesp_sta_has_ip()) {
 42        lwesp_delay(1000);
 43    }
 44
 45    /*
 46     * First create a new instance of netconn
 47     * connection and initialize system message boxes
 48     * to accept received packet buffers
 49     */
 50    client = lwesp_netconn_new(LWESP_NETCONN_TYPE_TCP);
 51    if (client != NULL) {
 52
 53        /*
 54         * Connect to external server as client
 55         * with custom NETCONN_CONN_HOST and CONN_PORT values
 56         *
 57         * Function will block thread until we are successfully connected (or not) to server
 58         */
 59        res = lwesp_netconn_connect(client, NETCONN_HOST, NETCONN_PORT);
 60        if (res == lwespOK) { /* Are we successfully connected? */
 61            printf("Connected to " NETCONN_HOST "\r\n");
 62            res = lwesp_netconn_write(client, request_header, sizeof(request_header) - 1); /* Send data to server */
 63            if (res == lwespOK) {
 64                res = lwesp_netconn_flush(client); /* Flush data to output */
 65            }
 66            if (res == lwespOK) { /* Were data sent? */
 67                printf("Data were successfully sent to server\r\n");
 68
 69                /*
 70                 * Since we sent HTTP request,
 71                 * we are expecting some data from server
 72                 * or at least forced connection close from remote side
 73                 */
 74                do {
 75                    /*
 76                     * Receive single packet of data
 77                     *
 78                     * Function will block thread until new packet
 79                     * is ready to be read from remote side
 80                     *
 81                     * After function returns, don't forgot the check value.
 82                     * Returned status will give you info in case connection
 83                     * was closed too early from remote side
 84                     */
 85                    res = lwesp_netconn_receive(client, &pbuf);
 86                    if (res
 87                        == lwespCLOSED) { /* Was the connection closed? This can be checked by return status of receive function */
 88                        printf("Connection closed by remote side...\r\n");
 89                        break;
 90                    } else if (res == lwespTIMEOUT) {
 91                        printf("Netconn timeout while receiving data. You may try multiple readings before deciding to "
 92                               "close manually\r\n");
 93                    }
 94
 95                    if (res == lwespOK && pbuf != NULL) { /* Make sure we have valid packet buffer */
 96                        /*
 97                         * At this point, read and manipulate
 98                         * with received buffer and check if you expect more data
 99                         *
100                         * After you are done using it, it is important
101                         * you free the memory, or memory leaks will appear
102                         */
103                        printf("Received new data packet of %d bytes\r\n", (int)lwesp_pbuf_length(pbuf, 1));
104                        lwesp_pbuf_free(pbuf); /* Free the memory after usage */
105                        pbuf = NULL;
106                    }
107                } while (1);
108            } else {
109                printf("Error writing data to remote host!\r\n");
110            }
111
112            /*
113             * Check if connection was closed by remote server
114             * and in case it wasn't, close it manually
115             */
116            if (res != lwespCLOSED) {
117                lwesp_netconn_close(client);
118            }
119        } else {
120            printf("Cannot connect to remote host %s:%d!\r\n", NETCONN_HOST, NETCONN_PORT);
121        }
122        lwesp_netconn_delete(client); /* Delete netconn structure */
123    }
124
125    printf("Terminating thread\r\n");
126    if (lwesp_sys_sem_isvalid(sem)) {
127        lwesp_sys_sem_release(sem);
128    }
129    lwesp_sys_thread_terminate(NULL); /* Terminate current thread */
130}

Netconn server

Netconn API server block diagram

Netconn API server block diagram

When netconn is configured in server mode, it is possible to accept new clients from remote side. Application creates netconn server connection, which can only accept clients and cannot send/receive any data. It configures server on dedicated port (selected by application) and listens on it.

When new client connects, server callback function is called with new active connection event. Newly accepted connection is then written to server structure netconn which is later read by application thread. At the same time, netconn connection structure (blue) is created to allow standard send/receive operation on active connection.

Note

Each connected client has its own netconn connection structure. When multiple clients connect to server at the same time, multiple entries are written to connection accept message queue and are ready to be processed by application thread.

From this point, program flow is the same as in case of netconn client.

This is basic example for netconn thread. It waits for client and processes it in blocking mode.

Warning

When multiple clients connect at the same time to netconn server, they are processed one-by-one, sequentially. This may introduce delay in response for other clients. Check netconn concurrency option to process multiple clients at the same time

Netconn server with single processing thread
 1/*
 2 * Netconn server example is based on single thread
 3 * and it listens for single client only on port 23.
 4 * 
 5 * When new client connects, application processes client in the same thread.
 6 * When multiple clients get connected at the same time, 
 7 * each of them waits all previous to be processed first, hence it may
 8 * introduce latency, in some cases even clearly visible in (for example) user browser 
 9 */
10#include "netconn_server_1thread.h"
11#include "lwesp/lwesp_netconn.h"
12#include "lwesp/lwesp.h"
13
14/**
15 * \brief           Basic thread for netconn server to test connections
16 * \param[in]       arg: User argument
17 */
18void
19netconn_server_1thread_thread(void* arg) {
20    lwespr_t res;
21    lwesp_netconn_p server, client;
22    lwesp_pbuf_p p;
23
24    LWESP_UNUSED(arg);
25
26    /* Create netconn for server */
27    server = lwesp_netconn_new(LWESP_NETCONN_TYPE_TCP);
28    if (server == NULL) {
29        printf("Cannot create server netconn!\r\n");
30    }
31
32    /* Bind it to port 23 */
33    res = lwesp_netconn_bind(server, 23);
34    if (res != lwespOK) {
35        printf("Cannot bind server\r\n");
36        goto out;
37    }
38
39    /* Start listening for incoming connections with maximal 1 client */
40    res = lwesp_netconn_listen_with_max_conn(server, 1);
41    if (res != lwespOK) {
42        goto out;
43    }
44
45    /* Unlimited loop */
46    while (1) {
47        /* Accept new client */
48        res = lwesp_netconn_accept(server, &client);
49        if (res != lwespOK) {
50            break;
51        }
52        printf("New client accepted!\r\n");
53        while (1) {
54            /* Receive data */
55            res = lwesp_netconn_receive(client, &p);
56            if (res == lwespOK) {
57                printf("Data received!\r\n");
58                lwesp_pbuf_free(p);
59            } else {
60                printf("Netconn receive returned: %d\r\n", (int)res);
61                if (res == lwespCLOSED) {
62                    printf("Connection closed by client\r\n");
63                    break;
64                }
65            }
66        }
67        /* Delete client */
68        if (client != NULL) {
69            lwesp_netconn_delete(client);
70            client = NULL;
71        }
72    }
73    /* Delete client */
74    if (client != NULL) {
75        lwesp_netconn_delete(client);
76        client = NULL;
77    }
78
79out:
80    printf("Terminating netconn thread!\r\n");
81    if (server != NULL) {
82        lwesp_netconn_delete(server);
83    }
84    lwesp_sys_thread_terminate(NULL);
85}

Netconn server concurrency

Netconn API server concurrency block diagram

Netconn API server concurrency block diagram

When compared to classic netconn server, concurrent netconn server mode allows multiple clients to be processed at the same time. This can drastically improve performance and response time on clients side, especially when many clients are connected to server at the same time.

Every time server application thread (green block) gets new client to process, it starts a new processing thread instead of doing it in accept thread.

  • Server thread is only dedicated to accept clients and start threads

  • Multiple processing thread can run in parallel to send/receive data from multiple clients

  • No delay when multi clients are active at the same time

  • Higher memory footprint is necessary as there are multiple threads active

Netconn server with multiple processing threads
  1/*
  2 * Netconn server example is based on single "user" thread
  3 * which listens for new connections and accepts them.
  4 *
  5 * When a new client is accepted by server,
  6 * a new thread gets spawned and processes client request 
  7 * separately. When multiple users are connected,
  8 * they can be processed simultaneously, hence no such latency as in single thread mode.
  9 * 
 10 * As a drawback, more memory is consumed for multiple parallel threads being potentially
 11 * used at the same period of time.
 12 */
 13#include "netconn_server.h"
 14#include "lwesp/lwesp_netconn.h"
 15#include "lwesp/lwesp.h"
 16
 17static void netconn_server_processing_thread(void* const arg);
 18
 19/**
 20 * \brief           Main page response file
 21 */
 22static const uint8_t
 23rlwesp_data_mainpage_top[] = ""
 24                           "HTTP/1.1 200 OK\r\n"
 25                           "Content-Type: text/html\r\n"
 26                           "\r\n"
 27                           "<html>"
 28                           "   <head>"
 29                           "       <link rel=\"stylesheet\" href=\"style.css\" type=\"text/css\" />"
 30                           "       <meta http-equiv=\"refresh\" content=\"1\" />"
 31                           "   </head>"
 32                           "   <body>"
 33                           "       <p>Netconn driven website!</p>"
 34                           "       <p>Total system up time: <b>";
 35
 36/**
 37 * \brief           Bottom part of main page
 38 */
 39static const uint8_t
 40rlwesp_data_mainpage_bottom[] = ""
 41                              "       </b></p>"
 42                              "   </body>"
 43                              "</html>";
 44
 45/**
 46 * \brief           Style file response
 47 */
 48static const uint8_t
 49rlwesp_data_style[] = ""
 50                    "HTTP/1.1 200 OK\r\n"
 51                    "Content-Type: text/css\r\n"
 52                    "\r\n"
 53                    "body { color: red; font-family: Tahoma, Arial; };";
 54
 55/**
 56 * \brief           404 error response
 57 */
 58static const uint8_t
 59rlwesp_error_404[] = ""
 60                   "HTTP/1.1 404 Not Found\r\n"
 61                   "\r\n"
 62                   "Error 404";
 63
 64/**
 65 * \brief           Netconn server thread implementation
 66 * \param[in]       arg: User argument
 67 */
 68void
 69netconn_server_thread(void const* arg) {
 70    lwespr_t res;
 71    lwesp_netconn_p server, client;
 72
 73    LWESP_UNUSED(arg);
 74
 75    /*
 76     * First create a new instance of netconn
 77     * connection and initialize system message boxes
 78     * to accept clients and packet buffers
 79     */
 80    server = lwesp_netconn_new(LWESP_NETCONN_TYPE_TCP);
 81    if (server != NULL) {
 82        printf("Server netconn created\r\n");
 83
 84        /* Bind network connection to port 80 */
 85        res = lwesp_netconn_bind(server, 80);
 86        if (res == lwespOK) {
 87            printf("Server netconn listens on port 80\r\n");
 88            /*
 89             * Start listening for incoming connections
 90             * on previously binded port
 91             */
 92            res = lwesp_netconn_listen(server);
 93
 94            while (1) {
 95                /*
 96                 * Wait and accept new client connection
 97                 *
 98                 * Function will block thread until
 99                 * new client is connected to server
100                 */
101                res = lwesp_netconn_accept(server, &client);
102                if (res == lwespOK) {
103                    printf("Netconn new client connected. Starting new thread...\r\n");
104                    /*
105                     * Start new thread for this request.
106                     *
107                     * Read and write back data to user in separated thread
108                     * to allow processing of multiple requests at the same time
109                     */
110                    if (lwesp_sys_thread_create(NULL, "client", (lwesp_sys_thread_fn)netconn_server_processing_thread, client, 512, LWESP_SYS_THREAD_PRIO)) {
111                        printf("Netconn client thread created\r\n");
112                    } else {
113                        printf("Netconn client thread creation failed!\r\n");
114
115                        /* Force close & delete */
116                        lwesp_netconn_close(client);
117                        lwesp_netconn_delete(client);
118                    }
119                } else {
120                    printf("Netconn connection accept error!\r\n");
121                    break;
122                }
123            }
124        } else {
125            printf("Netconn server cannot bind to port\r\n");
126        }
127    } else {
128        printf("Cannot create server netconn\r\n");
129    }
130
131    printf("Terminating thread\r\n");
132    lwesp_netconn_delete(server);                 /* Delete netconn structure */
133    lwesp_sys_thread_terminate(NULL);             /* Terminate current thread */
134}
135
136/**
137 * \brief           Thread to process single active connection
138 * \param[in]       arg: Thread argument
139 */
140static void
141netconn_server_processing_thread(void* const arg) {
142    lwesp_netconn_p client = arg;
143    lwesp_pbuf_p pbuf, p = NULL;
144    lwespr_t res;
145    char strt[20];
146
147    printf("A new connection accepted!\r\n");   /* Print simple message */
148
149    do {
150        /*
151         * Client was accepted, we are now
152         * expecting client will send to us some data
153         *
154         * Wait for data and block thread for that time
155         */
156        res = lwesp_netconn_receive(client, &pbuf);
157
158        if (res == lwespOK) {
159            printf("Netconn data received, %d bytes\r\n", (int)lwesp_pbuf_length(pbuf, 1));
160            /* Check reception of all header bytes */
161            if (p == NULL) {
162                p = pbuf;                       /* Set as first buffer */
163            } else {
164                lwesp_pbuf_cat(p, pbuf);        /* Concatenate buffers together */
165            }
166            /*
167             * Search for end of request section, that is supposed
168             * to end with line, followed by another fully empty line.
169             */
170            if (lwesp_pbuf_strfind(pbuf, "\r\n\r\n", 0) != LWESP_SIZET_MAX) {
171                if (lwesp_pbuf_strfind(pbuf, "GET / ", 0) != LWESP_SIZET_MAX) {
172                    uint32_t now;
173                    printf("Main page request\r\n");
174                    now = lwesp_sys_now();      /* Get current time */
175                    sprintf(strt, "%u ms; %d s", (unsigned)now, (unsigned)(now / 1000));
176                    lwesp_netconn_write(client, rlwesp_data_mainpage_top, sizeof(rlwesp_data_mainpage_top) - 1);
177                    lwesp_netconn_write(client, strt, strlen(strt));
178                    lwesp_netconn_write(client, rlwesp_data_mainpage_bottom, sizeof(rlwesp_data_mainpage_bottom) - 1);
179                } else if (lwesp_pbuf_strfind(pbuf, "GET /style.css ", 0) != LWESP_SIZET_MAX) {
180                    printf("Style page request\r\n");
181                    lwesp_netconn_write(client, rlwesp_data_style, sizeof(rlwesp_data_style) - 1);
182                } else {
183                    printf("404 error not found\r\n");
184                    lwesp_netconn_write(client, rlwesp_error_404, sizeof(rlwesp_error_404) - 1);
185                }
186                lwesp_netconn_close(client);    /* Close netconn connection */
187                lwesp_pbuf_free(p);             /* Do not forget to free memory after usage! */
188                p = NULL;
189                break;
190            }
191        }
192    } while (res == lwespOK);
193
194    if (p != NULL) {                            /* Free received data */
195        lwesp_pbuf_free(p);
196        p = NULL;
197    }                                           
198    lwesp_netconn_delete(client);               /* Destroy client memory */
199    lwesp_sys_thread_terminate(NULL);           /* Terminate this thread */
200}

Non-blocking receive

By default, netconn API is written to only work in separate application thread, dedicated for network connection processing. Because of that, by default every function is fully blocking. It will wait until result is ready to be used by application.

It is, however, possible to enable timeout feature for receiving data only. When this feature is enabled, lwesp_netconn_receive() will block for maximal timeout set with lwesp_netconn_set_receive_timeout() function.

When enabled, if there is no received data for timeout amount of time, function will return with timeout status and application needs to process it accordingly.

Tip

LWESP_CFG_NETCONN_RECEIVE_TIMEOUT must be set to 1 to use this feature.

group LWESP_NETCONN

Network connection.

Defines

LWESP_NETCONN_RECEIVE_NO_WAIT

Receive data with no timeout.

Note

Used with lwesp_netconn_set_receive_timeout function

Typedefs

typedef struct lwesp_netconn *lwesp_netconn_p

Netconn object structure.

Enums

enum lwesp_netconn_type_t

Netconn connection type.

Values:

enumerator LWESP_NETCONN_TYPE_TCP = LWESP_CONN_TYPE_TCP

TCP connection

enumerator LWESP_NETCONN_TYPE_SSL = LWESP_CONN_TYPE_SSL

SSL connection

enumerator LWESP_NETCONN_TYPE_UDP = LWESP_CONN_TYPE_UDP

UDP connection

enumerator LWESP_NETCONN_TYPE_TCPV6 = LWESP_CONN_TYPE_TCPV6

TCP connection over IPv6

enumerator LWESP_NETCONN_TYPE_SSLV6 = LWESP_CONN_TYPE_SSLV6

SSL connection over IPv6

enumerator LWESP_NETCONN_TYPE_UDPV6 = LWESP_CONN_TYPE_UDPV6

UDP connection over IPv6

Functions

lwesp_netconn_p lwesp_netconn_new(lwesp_netconn_type_t type)

Create new netconn connection.

Parameters

type[in] Netconn connection type

Returns

New netconn connection on success, NULL otherwise

lwespr_t lwesp_netconn_delete(lwesp_netconn_p nc)

Delete netconn connection.

Parameters

nc[in] Netconn handle

Returns

lwespOK on success, member of lwespr_t enumeration otherwise

lwespr_t lwesp_netconn_bind(lwesp_netconn_p nc, lwesp_port_t port)

Bind a connection to specific port, can be only used for server connections.

Parameters
  • nc[in] Netconn handle

  • port[in] Port used to bind a connection to

Returns

lwespOK on success, member of lwespr_t enumeration otherwise

lwespr_t lwesp_netconn_connect(lwesp_netconn_p nc, const char *host, lwesp_port_t port)

Connect to server as client.

Parameters
  • nc[in] Netconn handle

  • host[in] Pointer to host, such as domain name or IP address in string format

  • port[in] Target port to use

Returns

lwespOK if successfully connected, member of lwespr_t otherwise

lwespr_t lwesp_netconn_receive(lwesp_netconn_p nc, lwesp_pbuf_p *pbuf)

Receive data from connection.

Parameters
  • nc[in] Netconn handle used to receive from

  • pbuf[in] Pointer to pointer to save new receive buffer to. When function returns, user must check for valid pbuf value pbuf != NULL

Returns

lwespOK when new data ready

Returns

lwespCLOSED when connection closed by remote side

Returns

lwespTIMEOUT when receive timeout occurs

Returns

Any other member of lwespr_t otherwise

lwespr_t lwesp_netconn_close(lwesp_netconn_p nc)

Close a netconn connection.

Parameters

nc[in] Netconn handle to close

Returns

lwespOK on success, member of lwespr_t enumeration otherwise

int8_t lwesp_netconn_get_connnum(lwesp_netconn_p nc)

Get connection number used for netconn.

Parameters

nc[in] Netconn handle

Returns

-1 on failure, connection number between 0 and LWESP_CFG_MAX_CONNS otherwise

lwesp_conn_p lwesp_netconn_get_conn(lwesp_netconn_p nc)

Get netconn connection handle.

Parameters

nc[in] Netconn handle

Returns

ESP connection handle

lwesp_netconn_type_t lwesp_netconn_get_type(lwesp_netconn_p nc)

Get netconn connection type.

Parameters

nc[in] Netconn handle

Returns

ESP connection type

void lwesp_netconn_set_receive_timeout(lwesp_netconn_p nc, uint32_t timeout)

Set timeout value for receiving data.

When enabled, lwesp_netconn_receive will only block for up to timeout value and will return if no new data within this time

Parameters
  • nc[in] Netconn handle

  • timeout[in] Timeout in units of milliseconds. Set to 0 to disable timeout feature Set to > 0 to set maximum milliseconds to wait before timeout Set to LWESP_NETCONN_RECEIVE_NO_WAIT to enable non-blocking receive

uint32_t lwesp_netconn_get_receive_timeout(lwesp_netconn_p nc)

Get netconn receive timeout value.

Parameters

nc[in] Netconn handle

Returns

Timeout in units of milliseconds. If value is 0, timeout is disabled (wait forever)

lwespr_t lwesp_netconn_connect_ex(lwesp_netconn_p nc, const char *host, lwesp_port_t port, uint16_t keep_alive, const char *local_ip, lwesp_port_t local_port, uint8_t mode)

Connect to server as client, allow keep-alive option.

Parameters
  • nc[in] Netconn handle

  • host[in] Pointer to host, such as domain name or IP address in string format

  • port[in] Target port to use

  • keep_alive[in] Keep alive period seconds

  • local_ip[in] Local ip in connected command

  • local_port[in] Local port address

  • mode[in] UDP mode

Returns

lwespOK if successfully connected, member of lwespr_t otherwise

lwespr_t lwesp_netconn_listen(lwesp_netconn_p nc)

Listen on previously binded connection.

Parameters

nc[in] Netconn handle used to listen for new connections

Returns

lwespOK on success, member of lwespr_t enumeration otherwise

lwespr_t lwesp_netconn_listen_with_max_conn(lwesp_netconn_p nc, uint16_t max_connections)

Listen on previously binded connection with max allowed connections at a time.

Parameters
  • nc[in] Netconn handle used to listen for new connections

  • max_connections[in] Maximal number of connections server can accept at a time This parameter may not be larger than LWESP_CFG_MAX_CONNS

Returns

lwespOK on success, member of lwespr_t otherwise

lwespr_t lwesp_netconn_set_listen_conn_timeout(lwesp_netconn_p nc, uint16_t timeout)

Set timeout value in units of seconds when connection is in listening mode If new connection is accepted, it will be automatically closed after seconds elapsed without any data exchange.

Note

Call this function before you put connection to listen mode with lwesp_netconn_listen

Parameters
  • nc[in] Netconn handle used for listen mode

  • timeout[in] Time in units of seconds. Set to 0 to disable timeout feature

Returns

lwespOK on success, member of lwespr_t otherwise

lwespr_t lwesp_netconn_accept(lwesp_netconn_p nc, lwesp_netconn_p *client)

Accept a new connection.

Parameters
  • nc[in] Netconn handle used as base connection to accept new clients

  • client[out] Pointer to netconn handle to save new connection to

Returns

lwespOK on success, member of lwespr_t enumeration otherwise

lwespr_t lwesp_netconn_write(lwesp_netconn_p nc, const void *data, size_t btw)

Write data to connection output buffers.

Note

This function may only be used on TCP or SSL connections

Parameters
  • nc[in] Netconn handle used to write data to

  • data[in] Pointer to data to write

  • btw[in] Number of bytes to write

Returns

lwespOK on success, member of lwespr_t enumeration otherwise

lwespr_t lwesp_netconn_flush(lwesp_netconn_p nc)

Flush buffered data on netconn TCP/SSL connection.

Note

This function may only be used on TCP/SSL connection

Parameters

nc[in] Netconn handle to flush data

Returns

lwespOK on success, member of lwespr_t enumeration otherwise

lwespr_t lwesp_netconn_send(lwesp_netconn_p nc, const void *data, size_t btw)

Send data on UDP connection to default IP and port.

Parameters
  • nc[in] Netconn handle used to send

  • data[in] Pointer to data to write

  • btw[in] Number of bytes to write

Returns

lwespOK on success, member of lwespr_t enumeration otherwise

lwespr_t lwesp_netconn_sendto(lwesp_netconn_p nc, const lwesp_ip_t *ip, lwesp_port_t port, const void *data, size_t btw)

Send data on UDP connection to specific IP and port.

Note

Use this function in case of UDP type netconn

Parameters
  • nc[in] Netconn handle used to send

  • ip[in] Pointer to IP address

  • port[in] Port number used to send data

  • data[in] Pointer to data to write

  • btw[in] Number of bytes to write

Returns

lwespOK on success, member of lwespr_t enumeration otherwise