lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lwip-users] multiple servers with TCP


From: Michael
Subject: [lwip-users] multiple servers with TCP
Date: Tue, 12 Apr 2016 11:28:42 +0800 (CST)

Hi all
    I try to develop a multiple servers with netconn and freeRTOS, the application have a telnet server(port 23) and a gateway server(port 6020) in two tasks. Both servers are not accept the connection when the both tasks is running. but it can accept the connection and data when one server is working. what is happened? here is the code:
/*-----------------------------------------------------------------------------------*/
    struct netconn *sh_newconn;
    struct netconn *sh_conn;
static void shell_thread(void *arg)
{
    //struct netconn *conn, *newconn;
    err_t err;
    LWIP_UNUSED_ARG(arg);

    sh_conn = netconn_new(NETCONN_TCP);
    netconn_bind(sh_conn, NULL, 23);
    netconn_listen(sh_conn);

    while (1) {
        err = netconn_accept(sh_conn, &sh_newconn);
        if (err == ERR_OK) {
            send_str(welcome, sh_newconn);
            send_prompt(sh_newconn);
            shell_main(sh_newconn);
            netconn_delete(sh_newconn);
        }
    }
}
/*-----------------------------------------------------------------------------------*/
void shell_init(void)
{
    sys_thread_new("shell_thread", shell_thread, NULL, DEFAULT_THREAD_STACKSIZE, DEFAULT_THREAD_PRIO+1);
}
/*-----------------------------------------------------------------------------------*/

    struct netconn *gw_newconn;
    struct netconn *gw_conn;

static void network_thread(void *arg)
{
    static char welcome_msg[] = "CAN gateway is connected."NEWLINE;

//    struct netconn *gw_newconn;
//    struct netconn *gw_conn;
    err_t err;
    LWIP_UNUSED_ARG(arg);

    gw_newconn = NULL;
    gw_conn = netconn_new(NETCONN_TCP);
    err = netconn_bind(gw_conn, NULL, 6020);
    err = netconn_listen(gw_conn);

    while (1) {
        err = netconn_accept(gw_conn, &gw_newconn);
        if (err == ERR_OK) {
            sendstr( welcome_msg, gw_newconn);
            net_loop(gw_newconn);
            netconn_delete(gw_newconn);
            gw_newconn = NULL;
        }
    }
}
/*-----------------------------------------------------------------------------------*/
static void gateway_thread(void *arg)
{
    ........
}
/*-----------------------------------------------------------------------------------*/
int gateway_init(void)
{
    int ret;
    sys_thread_new("gateway", gateway_thread, NULL, DEFAULT_THREAD_STACKSIZE, DEFAULT_THREAD_PRIO);
    sys_thread_new("network", network_thread, NULL, DEFAULT_THREAD_STACKSIZE, DEFAULT_THREAD_PRIO+2);
    return TRUE;
}

Thank, 
Micheal


 


reply via email to

[Prev in Thread] Current Thread [Next in Thread]