lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lwip-users] invalid recvmbox in UDP recv() function


From: gussabina
Subject: [lwip-users] invalid recvmbox in UDP recv() function
Date: Wed, 10 May 2017 18:05:41 -0700 (MST)

Hello:

I'm using lwIP with FreeRTOS and I need to receive data via UDP. I'm testing
the following code which goes through until recv() function where it stucks
in the following line;

 LWIP_ERROR("netconn_accept: invalid recvmbox",
sys_mbox_valid(&conn->recvmbox), return ERR_CONN;);

inside netconn_recv( ) in api_lib.c

I'm currently using TCP sockets without problem and I also was able to send
data via UDP (in a similar example), but I'm stuck in this error while
receiving ....

Below is my example code. I would appreciate any help.

Regards;
Gus



/#include <lwip/sockets.h> 

#define RECEIVER_PORT_NUM 6001 
#define RECEIVER_IP_ADDR "192.136.23.21" 

void main(void)
{

int socket_fd;
struct sockaddr_in sa,ra;

int recv_data; char data_buffer[80]; 
/* Creates an UDP socket (SOCK_DGRAM) with Internet Protocol Family
(PF_INET).
 * Protocol family and Address family related. For example PF_INET Protocol
Family and AF_INET family are coupled.
*/

socket_fd = socket(PF_INET, SOCK_DGRAM, 0);

if ( socket_fd < 0 )
{

printf("socket call failed");
exit(0);
}

memset(&sa, 0, sizeof(struct sockaddr_in));
ra.sin_family = AF_INET;
ra.sin_addr.s_addr = inet_addr(RECEIVER_IP_ADDR);
ra.sin_port = htons(RECEIVER_PORT_NUM);


/* Bind the UDP socket to the port RECEIVER_PORT_NUM and to the current
* machines IP address (Its defined by RECEIVER_PORT_NUM).
* Once bind is successful for UDP sockets application can operate
* on the socket descriptor for sending or receiving data.
*/
if (bind(socket_fd, (struct sockaddr *)&ra, sizeof(struct sockaddr_in)) ==
-1)
{

printf("Bind to Port Number %d ,IP address %s
failed\n",RECEIVER_PORT_NUM,RECEIVER_IP_ADDR);
close(socket_fd);
exit(1);
}
/* RECEIVER_PORT_NUM is port on which Server waits for data to
* come in. It copies the received data into receive buffer and
* prints the received data as string. If no data is available it 
* blocks.recv calls typically return any availbale data on the socket
instead of waiting for the entire data to come.
*/

recv_data = recv(socket_fd,data_buffer,sizeof(data_buffer),0);
if(recv_data > 0)
{

data_buffer[recv_data] = '\0';
printf("%s\n",data_buffer);
} 
close(socket_fd);
}
/



--
View this message in context: 
http://lwip.100.n7.nabble.com/invalid-recvmbox-in-UDP-recv-function-tp29602.html
Sent from the lwip-users mailing list archive at Nabble.com.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]