Hi everyone!
Because I'm still suffering the same problem I should ask some fundamental questions.
Is it possible to use 2 connections in two different threads? Or must I handle both connections in a single thread?
As can be seen a in the code snippet of main.c I created three thread. One for lwip, one for communication at port 12345 and a webserver thread for port 80.
Code: Select all
int main(void)
{
/* IP settings */
uint8_t macaddress[] = {0x02,0x00,0x00,0x00,0x00,0x00};
struct lwipthread_opts lwip_configuration;
/*
* System initializations.
* - HAL initialization, this also initializes the configured device drivers
* and performs the board-specific initializations.
* - Kernel initialization, the main() function becomes a thread and the
* RTOS is active.
*/
halInit();
chSysInit();
/* Hardware initialization */
hardware_init();
/*
* Creates output handler thread.
*/
chThdCreateStatic(wa_output_handler,
sizeof(wa_output_handler),
HIGHPRIO,
output_handler,
NULL);
/*
* Creates the LWIP threads (it changes priority internally).
*/
macaddress[4] = serial;
macaddress[5] = hardware_address;
lwip_configuration.macaddress = macaddress;
IPADDR(lwip_configuration.address, 192, 168, 55, hardware_address);
IPADDR(lwip_configuration.netmask, 255, 255, 0, 0);
IPADDR(lwip_configuration.gateway, 192, 168, 0, 1);
chThdCreateStatic(wa_lwip_thread,
LWIP_THREAD_STACK_SIZE,
NORMALPRIO + 1,
lwip_thread,
&lwip_configuration);
/*
* Creates the comm thread (it changes priority internally).
*/
chThdCreateStatic(wa_comm_thread,
sizeof(wa_comm_thread),
NORMALPRIO,
comm_thread,
NULL);
/*
* Creates the HTTP thread (it changes priority internally).
*/
chThdCreateStatic(wa_http_server,
sizeof(wa_http_server),
LOWPRIO,
http_server,
NULL);
The code for the webserver looks like :
Code: Select all
msg_t http_server(void *p) {
struct netconn *conn, *newconn;
err_t err;
(void)p;
/* Create a new TCP connection handle */
conn = netconn_new(NETCONN_TCP);
LWIP_ERROR("http_server: invalid conn", (conn != NULL), return RDY_RESET;);
/* Bind to port 80 (HTTP) */
netconn_bind(conn, NULL, WEB_THREAD_PORT);
/* Put the connection into LISTEN state */
netconn_listen(conn);
/* Goes to the final priority after initialization.*/
chThdSetPriority(WEB_THREAD_PRIORITY);
while(1) {
err = netconn_accept(conn, &newconn);
if (err != ERR_OK) {
continue;
}
and similar the code for the communication at port 12345
Code: Select all
/**
* comm server thread.
*/
/*-------------------------------------------------------------------------*/
msg_t comm_thread(void *p) {
struct netconn *conn, *comm_conn;
err_t err;
(void)p;
/* Create a new TCP connection handle */
conn = netconn_new(NETCONN_TCP);
LWIP_ERROR("comm_server: invalid conn", (conn != NULL), return RDY_RESET;);
/* Bind to port 12345 */
netconn_bind(conn, NULL, COMM_THREAD_PORT);
/* Put the connection into LISTEN state */
netconn_listen(conn);
/* Goes to the final priority after initialization.*/
/* chThdSetPriority(COMM_THREAD_PRIORITY);*/
while (1) {
/* Blocks the process until a connection request from a remote host arrives.
netconn_listen() must be called prior to netconn_accept(). */
err = netconn_accept(conn, &comm_conn);
if (err != ERR_OK) {
continue;
}
The problem is, that if one connection is established, netconn_accept() doesn't return for the other thread.
May there is a special setting in lwipopts.h. I searched for weeks after this problem without any improvement.
So, I guess I did a fundamental mistake. Has anyone experience with Lwip using simultaniously multiple ports?
lG