lwIP Wiki
Advertisement

netconn_send[]

err_t netconn_send ( struct netconn * aNetConn, struct netbuf * aNetBuf );

Sends data to an UDP connection. Don't use for TCP!

  • in aNetConn : the netconn object created with netconn_new ( NETCONN_UDP )
  • in aNetBuf : the buffer containing the data. Created with netbuf_new()
  • return : ERR_OK or some error code
#define TNetConn struct netconn *
#define TNetBuf  struct netbuf  *


TNetConn xUdpConn = netconn_new ( NETCONN_UDP ); // could be NULL

struct TIpAddr  xIp;
xIp.addr = <my addr>;
UInt32 xRes = netconn_bind    ( xUdpConn, &xIp, 44444 )
            + netconn_connect ( xUdpConn, IP_ADDR_BROADCAST, 44444 );

if ( xRes == ERR_OK )
{
   Pointer xBuf = mem_malloc ( 1200 );  // could be NULL;
   memset ( xBuf, 0xAA, 1200 );   
   
    TNetBuf xNetBuf = netbuf_new ();
   netbuf_ref ( xNetBuf, xBuf, 1200 );
   xRes = netconn_send ( xUdpConn, xNetBuf );
   if ( xRes != ERR_OK )
   {
       <error>
    }
    else 
       ... ;
 
    netconn_delete ( xUdpConn );
   mem_free       ( xBuf );     // netbuf_free does NOT free this
   netbuf_delete  ( xNetBuf );
}

netconn_sendto[]

err_t netconn_sendto ( struct netconn * aNetConn, struct netbuf * aNetBuf,
                       ip_addr_t * aAddr, u16_t aPort );

This is the same as "netconn_send" except that you additionally pass the connection parameters.

(last changed: Sept. 26, 2011)

Advertisement