1

我正在尝试使用 lwip 包中的原始 tcp api 创建简单的应用程序。所以,这是我的代码的一部分:

err_t net_dg_accept(void *arg, struct tcp_pcb *con, err_t e)
{
  stm_debug("netdebug: accepting connection");
  const char *msg_t = "This is test debug message";
  tcp_write(con, msg_t, sizeof(msg_t),TCP_WRITE_FLAG_COPY);
  tcp_close(con);
}
void net_dg_thread ()
{
  stm_debug("netdebug: thread is starting");
  thrd_pcb = tcp_new();
  if (thrd_pcb != NULL) 
  {
    stm_debug("netdebug: thread_pcb was created");
    err_t e;
    e = tcp_bind(thrd_pcb, IP_ADDR_ANY, 22);
    if (e == ERR_OK)
    {
      stm_debug("netdebug: thread_pcb was binded!");
      lpcb = tcp_listen(thrd_pcb);
      stm_debug("netdebug: thread_pcb was put into listenning mode!");
      tcp_accept(lpcb,net_dg_accept);
      stm_debug("netdebug: ?");
    }
    else
    {
        stm_debug("netdebug: error while binding thread_pcb!");
    }
  }
  else
  {
    stm_debug("netdebug: error while creating thread_pcb!");
  }
}

我尝试连接到 22 端口,但我什么也没得到。从串行调试中,我得知 thrd_pcb 已成功进入侦听模式。为什么会这样?

4

0 回答 0