lwip-users
[Top][All Lists]
Advanced

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

[lwip-users] udp netconn_recv (v1.4.1) issue


From: newbie
Subject: [lwip-users] udp netconn_recv (v1.4.1) issue
Date: Wed, 12 Jul 2017 04:43:24 -0700 (MST)

hello network,
I'm using LwIP v1.4.1 ontop of freeRTOS
I've developed a UDP client using netconn API. In simple echo test it could
send correctly however netconn_recv() times out (or gets blocked if timeout
is disabled).
NB: the server run on posix plateform

/*The client code is:
****************************************************************************/
struct netconn *l_psOutConn;
struct netbuf *l_psOutNetBuf;
struct netbuf *l_psInNetBuf;
struct ip_addr l_sHostIpAddr, l_sServerIPAddr;
err_t l_eConnErr = ERR_OK;

/* wait until getting valid IP address */
  ...

while (TRUE)
{
  l_eConnErr = ERR_OK;

  /* create a new connection */
  l_psOutConn = netconn_new(NETCONN_UDP);

  /* connect the connection to the remote host */
  l_eConnErr |= netconn_connect(l_psOutConn, IP_ADDR_BROADCAST,
1234);//&l_sServerAddr, 1234);

  /* create a new netbuf */
  l_psOutNetBuf = netbuf_new();
  l_psInNetBuf = netbuf_new();

  /* reference the text into the netbuf */
  l_eConnErr |= netbuf_ref(l_psOutNetBuf, g_pcOutData, sizeof(g_pcOutData));
  l_eConnErr |= netbuf_ref(l_psInNetBuf , g_pcInData, sizeof(g_pcInData));

  /* echo process */
  int counter = 0;
  while (l_eConnErr == ERR_OK)
  {
    snprintf(g_pcOutData, sizeof(g_pcOutData), "message number: %d\n\r"\
               "A static text for testing\n\r", counter);
    l_eConnErr |= netconn_sendto(l_psOutConn, l_psOutNetBuf,
                                              IP_ADDR_BROADCAST,
D_iServerOverUDPPort);

    /* avoid blocking */
//   netconn_set_recvtimeout(l_psOutConn, 20);

    /* receive echo data */
    if (l_eConnErr == ERR_OK)
//    while (TRUE)
    {
      l_eConnErr |= netconn_recv(l_psOutConn, &l_psOutNetBuf);   // it
stucks here!
    }

  counter++;
  netconn_set_recvtimeout(l_psOutConn, 0);
  vTaskDelay(100);
}

    /* deallocate connection and netbuf */
    netbuf_delete(l_psOutNetBuf);
    netbuf_delete(l_psInNetBuf);
    l_eConnErr |= netconn_delete(l_psOutConn);
 }


/*A simple UDP server is nearly:
****************************************************************************/
  /* respond on data reception */
  if ((retVal = recvfrom(socketFd, buf, BUFLEN, 0, (struct
sockaddr*)&si_other, &slen))>=0)
  {
      /* receiving succedes */
      printf("Received %d bytes from %s:%d\nData: %s\n\n", retVal, 
      inet_ntoa(si_other.sin_addr), ntohs(si_other.sin_port), buf);

      printf("sending back...\n");
      snprintf(buf, BUFLEN, "server coordinates:  IP<%s> Port
number<%d>\r\n", inet_ntoa(si_me.sin_addr), PORT);

// si_other.sin_port = htons(PORT);
      
      while(1)
      {
        /* sendto returns OK */
        if(sendto(socketFd, buf, strlen(buf)+1, 0, (struct sockaddr*)
&si_other, sizeof(si_other)) >= 0)
        {
          printf("data sent to %s:%d\r\n", inet_ntoa(si_other.sin_addr),
ntohs(si_other.sin_port));
        }
        else
        {
          printf("error sending!\r\n");
        }
        usleep(50000);   // prevent overhead
      }
    
  }

Thank you in advance



--
View this message in context: 
http://lwip.100.n7.nabble.com/udp-netconn-recv-v1-4-1-issue-tp30122.html
Sent from the lwip-users mailing list archive at Nabble.com.



reply via email to

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