lpc4330 lwip tcpecho_client

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

lpc4330 lwip tcpecho_client

1,511 Views
li-chinwang
Contributor II

I follow the some suggestion and modify tcpecho example to tcpecho_client.

Though it works. But system will crash every 30 mins if it has connected with tcp server like below.

I think the problem is pbuf allocation is run out and reset. 

Is that any way to fix this issue.

GATEWAY_IP : 192.168.1.2
Ping_IP Sent : 192.168.1.25
lwip_sendto(0, data=0x100016e0, short_size=40, flags=0x0 to=192.168.1.25 port=16
ping: send PingSend192.168.1.25
_Done
recv_start lwip_recvfrom(0, 0x10006294, 64z, 0x0, ..)
lwip_recvfrom: top while sock->lastdata=0x0
lwip_recvfrom: netconn_recv err=0, netbuf=0x100017a8
lwip_recvfrom: buflen=60 len=64z off=0 sock->lastoffset=0
lwip_recvfrom(0): addr=192.168.1.25 port=1 len=60
lwip_recvfrom: deleting netbuf=0x100017a8
ping: recv 0.0.0.97 63 ms
PingReturn OK
pbuf_free: sane type:637 in file ../lwip/core/pbuf.c

static void
tcpecho_thread(void *arg)
{
struct netconn *conn, *newconn;
err_t err;
int i,j=0;
LWIP_UNUSED_ARG(arg);
uint32_t len;

char rx_array[20];

/* Create a new connection identifier. */
conn = netconn_new(NETCONN_TCP);


#ifdef Server
/* Bind connection to well known port number 7. */
netconn_bind(conn, NULL, 234);
#else
netconn_bind(conn, IP_ADDR_ANY, 234);
#endif

/* Tell connection to go into listening mode. */

#ifdef SERVER
netconn_listen(conn);
#else
ip_addr_t IpAdd;
IP4_ADDR(&IpAdd, 192, 168, 0, 237);
//IP4_ADDR(&IpAdd, 18, 235, 222, 172);
#endif

while (1)
{

struct netbuf *buf;
void *data;
u16_t len;
int message_flag=0;

/* Grab new connection. */

#ifdef SERVER
err = netconn_accept(conn, &newconn);
#else
if(err!=ERR_OK)
{
err=netconn_connect(conn, &IpAdd, 8080);
printf("Connect to TCP Server with %d\r\n",err);
}

for(i=0;i<20;i++)
{
message[i]=0x0;
}
strcpy(message,"Test Code\r\n");
message_flag=1;

#endif

if (err == ERR_OK)
{

#ifdef SERVER

while ((err = netconn_recv(newconn, &buf)) == ERR_OK)
{
/*printf("Recved\n");*/
do {
netbuf_data(buf, &data, &len);
err = netconn_write(newconn, data, len, NETCONN_COPY);
} while (netbuf_next(buf) >= 0);
netbuf_delete(buf);
}
/* Close connection and discard connection identifier. */
netconn_close(newconn);
netconn_delete(newconn);

#else

if(message_flag==1)
{
//err=netconn_write(conn, message, sizeof(message), NETCONN_NOFLAG);
for(i=0;i<20;i++)
{
message[i]=0x0;
}
//sprintf(message,"Head%d",j);
//printf("%s \r\n",message);
sprintf(message,"Head%d",j);
printf("%s \r\n",message);
//printf("%s\r\n",http_string);
err=netconn_write(conn,message,strlen(message), NETCONN_NOFLAG);

if((err = netconn_recv(conn, &buf)) == ERR_OK)
{
do
{
netbuf_data(buf, &data, &len);
//err = netconn_write(newconn, data, len, NETCONN_COPY);

} while (netbuf_next(buf) >= 0);

strncpy(rx_array,(char *)data,len);
rx_array[len]='\0';
printf("%s\r\n",rx_array);
netbuf_delete(buf);
for(i=0;i<20;i++)
{
message[i]=0x0;
}
sprintf(message,"Tail%d",j);
printf("%s \r\n",message);
err=netconn_write(conn, message, sizeof(message), NETCONN_NOFLAG);
}

//netbuf_delete(buf);
message_flag=0;
//netconn_close(conn);
//netconn_delete(conn);
}
#endif


if(fr_cnt%10000==0)
{
for(i=0;i<20;i++)
{
message[i]=0x0;
}
strcpy(message,"Test Code\r\n");
message_flag=1;

}
if(fr_cnt<4000000)
fr_cnt++;
else
fr_cnt=0;
j++;

}

}
}
/*-----------------------------------------------------------------------------------*/

0 Kudos
1 Reply

1,122 Views
danielchen
NXP TechSupport
NXP TechSupport

Hi Li-chin:

There is one similar issue, I would suggest you refer to below link

https://community.nxp.com/message/1081486 

Regards

Daniel

0 Kudos