打印
[uCOS/RTOS]

ucos lwip连接建立问题

[复制链接]
1380|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
aifei7320|  楼主 | 2014-3-10 13:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 aifei7320 于 2014-3-10 13:55 编辑

        我使用以下两个函数,作为ucos中的任务,想要建立两个tcp连接,但是使用调试工具发现,链接建立瞬间即关闭。而如果只建立任意一个任务,则连接可以使用,http可以登录,tcp也可以发送接收数据。想问问大侠们知不知道是什么原因导致的。
tcpecho_thread(void *arg)
{
  struct netconn *conn, *newconn;
  err_t err;
  LWIP_UNUSED_ARG(arg);


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


  /* Bind connection to well known port number 7. */
  netconn_bind(conn, NULL, 7);


  /* Tell connection to go into listening mode. */
  netconn_listen(conn);


  while (1) {


    /* Grab new connection. */
    err = netconn_accept(conn, &newconn);
    /*printf("accepted new connection %p\n", newconn);*/
    /* Process the new connection. */
    if (err == ERR_OK) {
      struct netbuf *buf;
      void *data;
      u16_t len;
      
      while ((err = netconn_recv(newconn, &buf)) == ERR_OK) {
        /*printf("Recved\n");*/
        do {
             netbuf_data(buf, &data, &len);
             err = netconn_write(newconn, data, len, NETCONN_COPY);
#if 0
            if (err != ERR_OK) {
              printf("tcpecho: netconn_write: error \"%s\"\n", lwip_strerr(err));
            }
#endif
        } while (netbuf_next(buf) >= 0);
        netbuf_delete(buf);
      }
      /*printf("Got EOF, looping\n");*/
      /* Close connection and discard connection identifier. */
      netconn_close(newconn);
      netconn_delete(newconn);
    }
  }
}
static void
http_server_netconn_thread(void *arg)
{
  struct netconn *conn, *newconn;
  err_t err;
  LWIP_UNUSED_ARG(arg);
  
  /* Create a new TCP connection handle */
  conn = netconn_new(NETCONN_TCP);
  LWIP_ERROR("http_server: invalid conn", (conn != NULL), return;);
  
  /* Bind to port 80 (HTTP) with default IP address */
  netconn_bind(conn, NULL, 80);
  
  /* Put the connection into LISTEN state */
  netconn_listen(conn);
  
  do {
    err = netconn_accept(conn, &newconn);
    if (err == ERR_OK) {
      http_server_netconn_serve(newconn);
    }
  } while(err == ERR_OK);
  LWIP_DEBUGF(HTTPD_DEBUG,
    ("http_server_netconn_thread: netconn_accept received error %d, shutting down",
    err));
  netconn_close(conn);
  netconn_delete(conn);
}




相关帖子

发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

8

主题

48

帖子

1

粉丝