I am working on my first project using LWIP 1.4.1 and I am having some trouble. 
What I need the software to do is to listen on a port for a message from a 
remote machine and send a response. After it sends the response it needs to 
send a command to the same remote machine and await a response. I have the 
first part working fine with the code below. I can listen for a message and 
send the response with the code below. The problem is with the second part, 
having the system then send a command to the remote system and wait for a 
response. If I simply generate the command and send it right after the initial 
response the remote system doesn't see it. I have also tried making a separate 
task that would be triggered by the receive task. The second task creates a new 
netconn and connects to the remote host. This works for a short while but the 
responses from the commands are not being processed and shortly fill the memory.

Does anyone have any suggestions? I have been stuck on this for a few days now 
and I am all out of ideas.

Thanks
Keith


static void vInterlockTask1(void *pvParameters)
{
       struct netconn *conn, *newconn;
       err_t err;
       LWIP_UNUSED_ARG(pvParameters);
       struct netbuf *buf;
       uint8_t data[128];
       uint8_t *dataPtr;
       uint16_t len;

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

       /* Bind connection to the port number. */
       err = netconn_bind(conn, NULL, INTERLOCK_PORT_1);
       if (err != ERR_OK)
       {
              printf("Netcon Bind Error Status: %d\n",err);
       }

       /* Tell connection to go into listening mode. */
       err = netconn_listen(conn);
       if (err != ERR_OK)
       {
              printf("Netcon Listen Error Status: %d\n",err);
       }

       while(1)
       {
              if ((err = netconn_accept(conn, &newconn)) == ERR_OK)
              {
                     while ((err = netconn_recv(newconn, &buf)) == ERR_OK)
                     {
                      do
                      {
                            netbuf_data(buf, (void**)&dataPtr, &len);
                            memcpy(&data[0],dataPtr,len);
                            RequestProcessor( dataPtr, &rspBuf[0], &rspLength );

                           // Send the response back
                           err = netconn_write(newconn, (void *)&data[0], len, 
NETCONN_COPY);
                           if (err != ERR_OK)
                           {
                                  printf("Error Status: %d\n",err);
                           }

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

                      netbuf_delete(buf);

                     /* Command to remote system goes here??? */
                     }
              }
              netconn_close(newconn);
              netconn_delete(newconn);

              printf("Newconn error: %d\n",err);
       }
}
_______________________________________________
lwip-users mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/lwip-users

Reply via email to