无法使用原始tcp(lwIp)接受连接

时间:2014-04-09 11:41:26

标签: tcp lwip

我尝试使用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成功进入监听模式。为什么会如此?

0 个答案:

没有答案