cancel
Showing results for 
Search instead for 
Did you mean: 

lwIp netconn API UDP connection

Pawan Kumar sharma
Associate II
Posted on April 27, 2018 at 08:28

please tell me more about UDP PORT:-

 

this is my code:-(Is it correct or not)

void StartDefaultTask(void const * argument)

{

/* init code for LWIP */

MX_LWIP_Init();

/* USER CODE BEGIN 5 */

/* conn = netconn_new( NETCONN_UDP );

netconn_bind(conn,IP_ADDR_ANY, 7); //local port

netconn_connect(conn, IP_ADDR_BROADCAST, 1235 );

*/

conn = netconn_new(NETCONN_UDP);

if(conn!=NULL)

{

HAL_UART_Transmit(&huart3,'new\r\n',5,100);

HAL_Delay(100);

}

/* set up the IP address of the remote host */

addr.addr = htonl(0xC0A86472);

/* connect the connection to the remote host */

if(netconn_bind(conn,&addr,55555)==ERR_OK)

{

HAL_UART_Transmit(&huart3,'bind\r\n',6,100);

HAL_Delay(100);

}

if( netconn_connect(conn,&addr,0)==ERR_OK)

{

HAL_UART_Transmit(&huart3,'connect\r\n',9,100);

HAL_Delay(100);

}

/* Infinite loop */

for(;;)

{

/* create a new netbuf */

HAL_UART_Transmit(&huart3,'default\r\n',9,100);

HAL_Delay(100);

buf = netbuf_new();

if(buf!=NULL)

{

HAL_UART_Transmit(&huart3,'netbuf_new\r\n',12,100);

HAL_Delay(100);

}

data = netbuf_alloc(buf, 10);

if(data!=NULL)

{

HAL_UART_Transmit(&huart3,'netbuf_alloc\r\n',14,100);

HAL_Delay(100);

}

/* create some arbitrary data */

for(i = 0; i < 10; i++)

data[i] = 'a';

/* send the arbitrary data */

if(netconn_send(conn, buf)==ERR_OK)

{

HAL_UART_Transmit(&huart3,'sending1\r\n',10,100);

HAL_Delay(100);

}

vTaskDelay( 200 ); //some delay!

/* reference the text into the netbuf */

if(netbuf_ref(buf, text, sizeof(text))==ERR_OK)

{

HAL_UART_Transmit(&huart3,'netbuf_ref\r\n',12,100);

HAL_Delay(100);

}

/* send the text */

if(netconn_sendto(conn,buf,&addr,55555)==ERR_OK)

{

HAL_UART_Transmit(&huart3,'sending2\r\n',10,100);

HAL_Delay(100);

}

vTaskDelay( 200 ); //some delay!

/* deallocate connection and netbuf */

netbuf_delete(buf);

osDelay(1);

}

/* USER CODE END 5 */

}

#lwip* #udp #netconn #freertos
0 REPLIES 0