1
我嘗試使用LwIP netconn API(在stm32f4發現板上)建立多個同時連接。他們都在自己的線程和完美的工作。但由於某種原因,只能同時建立一個連接。使用netconn同時處理多個LwIP連接
我的代碼是基於ST回聲服務器的例子,看起來像這樣:
void myTaskStart(void const * argument)
{
struct netconn *conn, *newconn;
err_t err, accept_err;
struct netbuf* buf;
void* data;
u16_t len;
err_t recv_err;
/* Create a new connection identifier. */
conn = netconn_new(NETCONN_TCP);
if (conn != NULL)
{
err = netconn_bind(conn, NULL, <some port>);
if (err == ERR_OK)
{
/* Tell connection to go into listening mode. */
netconn_listen(conn);
while (1)
{
/* Grab new connection. */
accept_err = netconn_accept(conn, &newconn);
/* Process the new connection. */
if (accept_err == ERR_OK)
{
<do stuff here>
netconn_close(newconn);
netconn_delete(newconn);
}
}
}
else
{
netconn_delete(newconn);
printf(" can not bind TCP netconn");
}
}
else
{
printf("can not create TCP netconn");
}
}
所有線程都在聽不同的端口。但是如果另一個使用不同端口的連接已經建立,所有其他線程將在netconn_accept
處失敗。它返回ERR_ABRT
這意味着a connection has been aborted: out of pcbs or out of netconns during accept
。 我在這裏錯過了什麼?