You are creating a new task here

 if(sys_thread_new("AcceptThread", New_Accept_Thread,
NULL, 512, 2) == NULL)
                                   LWIP_ASSERT("tcpecho(): New Accept Task

in the very next line you are closing connection here

netconn_close(newconn);
netconn_delete(newconn);


the code does not guarantee that your connection will be alive by the time
your created task (New_Accept_Thread) come to execution.

Sol : why you want to create a task when the data is received instead you
can create a function. that will solve your problem.

Regards,
Mohsin Madki.

On Mon, Jan 1, 2018 at 3:10 PM, abdullah246 <[email protected]>
wrote:

> Hello, I am using FRDM-K64F and have changed the TCP echo+ freeRTOS
> according
> to my need. I want a task that is always In a listening state. Whenever a
> new client gets connected a new task should be created and some functions
> should be added there. I am using the netconn api. I tried making the
> struct netconn *conn, *newconn; global as I need the descriptor for
> netconn_write in another task. But I get an error : netconn_write: invalid
> conn . The code is as follows: -
>
> #include "tcpecho.h"
>
> #include "lwip/opt.h"
>
> #if LWIP_NETCONN
>
> #include "lwip/sys.h"
> #include "lwip/api.h"
>
> /*----------------------------------------------------------
> -------------------------*/
> int threadid = 0;
> const struct netconn *conn, *newconn;
> err_t err;
>
> static void New_Accept_Thread(void *pvParameters)
> {
>                 err_t err;
>                 char text[] = "Abdullah Shafiq";
>                 threadid ++;
>                 PRINTF("In New_Accept_Thread id = %d\r\n",threadid);
>
>                 while (1)
>                 {
>
>                                                  for(;;)
>                                                  {
>                                   err = netconn_write(newconn, text,
> sizeof(text), NETCONN_COPY);
>                                   vTaskDelay(100);
>                                                  }
>
>                 }
> }
> static void
> tcpecho_thread(void *arg)
> {
>     struct netbuf *buf;
>     void *data;
>     u16_t len;
>     LWIP_UNUSED_ARG(arg);
>
>   conn = netconn_new(NETCONN_TCP);
>   netconn_bind(conn, IP_ADDR_ANY, 5000);
> #endif /* LWIP_IPV6 */
>   LWIP_ERROR("tcpecho: invalid conn", (conn != NULL), return;);
>
>   netconn_listen(conn);
>
>   while (1)
>   {
>                 err = netconn_accept(conn, &newconn);
>                 if (err == ERR_OK)
>                 {
>
>                    if(sys_thread_new("AcceptThread", New_Accept_Thread,
> NULL, 512, 2) == NULL)
>                                    LWIP_ASSERT("tcpecho(): New Accept Task
> creation failed.", 0);
>
>
>
>                  netconn_close(newconn);
>                  netconn_delete(newconn);
>
>                   } // if Accept Successfull
>   }
> }
> I tried commenting out netconn_close and netconn_delete but got no success
>
>
>
>
> --
> Sent from: http://lwip.100.n7.nabble.com/lwip-users-f3.html
>
> _______________________________________________
> lwip-users mailing list
> [email protected]
> https://lists.nongnu.org/mailman/listinfo/lwip-users
>
_______________________________________________
lwip-users mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/lwip-users

Reply via email to