Hi,
I'm using LwIP and FreeRTOS to develope a simple client/server application with STM3220G board.
The client (running on PC) connects to server and then sends a message every 2 seconds.
The server (running on STM3220G board) processes the incoming message and replies with an appropriate response.
After a fixed number of read/write, the server netconn_recv() returns NULL and the connection error is equal to ERR_CLSD. It seems a memory allocation problem.
Unlike what has been done in the examples, after the netconn_accept() the connection is kept open: the server doesn't call netconn_close() and netconn_delete() after netconn_write(). Is this allowed?
The server code is like the following:
static void thread_1(void *arg)
{
conn = netconn_new(NETCONN_TCP);
if (conn!= NULL)
{
err = netconn_bind(conn, NULL, 9229);
if (err == ERR_OK)
{
netconn_listen(conn);
while(1)
{
if (CONN_NUM < 1)
{
MY_CONN = netconn_accept(conn);
CONN_NUM++;
}
else
{
vTaskDelay(500);
}
}
}
}
}
static void thread_2(void *arg)
{
for (;;)
{
if (CONN_NUM > 0)
{
inbuf = netconn_recv(MY_CONN);
if (inbuf != NULL)
{
if (netconn_err(MY_CONN) == ERR_OK)
{
netbuf_data(inbuf, (void**)&recv_buf, &recv_buflen);
if (recv_buflen >= 9)
{
msg_id = recv_buf[4];
switch (msg_id)
{
case MSG_1:
//...
netconn_write(MY_CONN, (const unsigned char*)send_buff, (size_t)send_buflen, NETCONN_NOCOPY);
break;
case MSG_2:
//...
netconn_write(MY_CONN, (const unsigned char*)send_buff, (size_t)send_buflen, NETCONN_NOCOPY);
break;
default:
break;
}
}
while( netbuf_next(inbuf) >= 0 ){}
}
netbuf_delete(inbuf);
}
vTaskDelay(10);
}
else
{
vTaskDelay(500);
}
}
}
Thanks.
--
Damiano Grechi