我的代码基于ST echo服务器示例,如下所示
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
.