Karenjon 发表于 2011-9-19 17:55:47

ucos+lwip中的关于netconn接口UDP通信问题请教

问大家一个问题,下面是我ucos+lwip中的关于netconn接口UDP通信,先能接收到数据,一发送数据就死机。找了两天都没有找到问题,郁闷。TCP通信都是没有问题的。       

    static struct netconn *conn;
        static struct netbuf*UDPNetbuf;
        static struct ip_addr *addr;
        static unsigned short port;       
        unsigned char Array;
        int DataLen,i;

        conn = netconn_new(NETCONN_UDP);       /* 创建UDP连接*/
        netconn_bind(conn, NULL,23);

        while(1)
        {
                UDPNetbuf = netconn_recv(conn);                                //接受数据
                addr = netbuf_fromaddr(UDPNetbuf);
                port = netbuf_fromport(UDPNetbuf);
               


                netconn_connect(conn, addr, port);

                netconn_send(conn, UDPNetbuf);
                     
                netbuf_delete(UDPNetbuf);
        }

Karenjon 发表于 2011-9-20 16:29:26

还是我自己来。问题得到解决:
{
        static struct netconn *conn;
        static struct netbuf*UDPNetbuf;
        static struct ip_addr *addr;
        static struct ip_addr destip;
        static unsigned short port;       
        unsigned char Array;
        char *pTemp;
        int DataLen;

        conn = netconn_new(NETCONN_UDP);       /* 创建UDP连接*/

        netconn_bind(conn, IP_ADDR_ANY, 23);

        while(1)
        {
                UDPNetbuf = netconn_recv(conn);                                //接受数据

                addr = netbuf_fromaddr(UDPNetbuf);
                port = netbuf_fromport(UDPNetbuf);
                destip = *addr;


          netconn_connect(conn, &destip, port);

                netbuf_copy(UDPNetbuf, Array, UDPNetbuf->p->tot_len);

                Array = '\0';

          UDPNetbuf->addr=&destip;

      UDPNetbuf->port=port;

          netconn_send(conn, UDPNetbuf);

      netbuf_delete(UDPNetbuf);
        }       
}

wang1216 发表于 2011-9-21 12:05:29

我也犯过同样的错误,不能直接转发。。。

zhoudandandan 发表于 2011-9-21 20:01:41

楼主,你的是什么版本啊....我也调了n天..就是发送数据死机..我的是1.2.0版本..你的TCP通信可以贴出来看看不?谢谢你了.

Karenjon 发表于 2011-9-27 11:34:23

回复【3楼】zhoudandandan 豆豆幻想
-----------------------------------------------------------------------

我这个是UDP,TCP是类似。

expressme 发表于 2011-10-8 11:32:18

这个是TCP的
{
    struct netconn *conn, *newconn = NULL;
    struct netbuf        *TCPNetbuf;
   
        UARTprintf("TCP_Test_task\n");

    conn = netconn_new(NETCONN_TCP);      /* 创建TCP连接*/
   
    netconn_bind(conn,NULL,80);         /* 绑定本地地址和监听的端口号 */
   
    netconn_listen(conn);               /* 进入监听状态 */
    while(1)
    {
      newconn = netconn_accept(conn);    /*阻塞当前进程到有数据接收 */
      if(newconn != NULL)
      {   
            if((TCPNetbuf = netconn_recv(newconn)) != NULL)
            {
               
                netconn_write(newconn,(void *)http_html_hdr,sizeof(http_html_hdr),NETCONN_NOCOPY);
                                           /* 发送头部数据*/
                netconn_write(newconn,(void *)indexdata,sizeof(indexdata),NETCONN_NOCOPY);
                                           /* 发送实际的WEB页面 */
                               
                netbuf_delete(TCPNetbuf);
            }         
            netconn_close(newconn);       /* 关闭连接   */
            
          while(netconn_delete(newconn) != ERR_OK)
          OSTimeDlyHMSM(0, 0, 1, 0);
      }
    }
}

frank2012 发表于 2012-1-17 19:47:48

我的也是UDP不通

糖糖love丽 发表于 2013-8-26 19:49:00

markmark

changtf 发表于 2013-11-8 10:26:56

强烈请求楼主开源{:dizzy:}

beyondme37 发表于 2014-1-17 14:29:20

楼主udp怎么搞定的啊{:dizzy:}
页: [1]
查看完整版本: ucos+lwip中的关于netconn接口UDP通信问题请教