U are right, but I don't know where the mistake is. I can debug it and the
breakpoints in myCallback1 and myCallback2 are hit.
The also debugged the init_Server and the binding or listen gave no error.
Both connections are initiated correctly.
I do init:
void init_Server(void)
{
struct tcp_pcb *pcb_1;
struct tcp_pcb *pcb_2;
pcb_1 = tcp_new();
pcb_2 = tcp_new();
tcp_bind(pcb_1, IP_ADDR_ANY, PortCAN1);
tcp_bind(pcb_2, IP_ADDR_ANY, PortCAN2);
pcb_1->flags |= TF_NODELAY;
pcb_1->flags |= TF_ACK_NOW;
pcb_2->flags |= TF_NODELAY;
pcb_2->flags |= TF_ACK_NOW;
tcp_arg(pcb_1, pcb_1);
tcp_arg(pcb_2, pcb_2);
pcb_1 = tcp_listen(pcb_1);
pcb_2 = tcp_listen(pcb_2);
tcp_accept(pcb_1, accept);
tcp_accept(pcb_2, accept);
}
static err_t accept(void *arg, struct tcp_pcb *pcb, err_t err)
{
LWIP_UNUSED_ARG(arg);
LWIP_UNUSED_ARG(err);
// set the receive callback for this connection
if(pcb->local_port == PortCAN1)
{
tcp_setprio(pcb, TCP_PRIO_MAX);
tcp_recv(pcb, myCallback1);
}
else if(pcb->local_port == PortCAN2)
{
tcp_setprio(pcb, TCP_PRIO_MAX);
tcp_recv(pcb, myCallback2);
}
// just use an integer number indicating the connection id as the
// callback argument
tcp_arg(pcb, (void*)pcb);
// Inform lwIP that an incoming connection has been accepted.
tcp_accepted( pcb );
return ERR_OK;
}
static err_t myCallback1(void *arg, struct tcp_pcb *tpcb, struct pbuf *p,
err_t err)
{
// avoid compiler warnings
( void ) arg;
( void ) err;
char data[8] = {1,2,3,4,5,6,7,8};
if (!p) //end of linked list
{
tcp_close(tpcb);
tcp_recv(tpcb, NULL);
return ERR_OK;
}
tcp_recved(tpcb, p->tot_len); //Antwort
tcp_write(tpcb, &data[0], 8, TCP_WRITE_FLAG_COPY);
tcp_output(tpcb);
pbuf_free(p);
return ERR_OK;
}
static err_t myCallback2(void *arg, struct tcp_pcb *tpcb, struct pbuf *p,
err_t err)
{
// avoid compiler warnings
( void ) arg;
( void ) err;
char data[8] = {1,2,3,4,5,6,7,8};
if (!p) //end of linked list
{
tcp_close(tpcb);
tcp_recv(tpcb, NULL);
return ERR_OK;
}
tcp_recved(tpcb, p->tot_len); //Antwort
tcp_write(tpcb, &data[0], 8, TCP_WRITE_FLAG_COPY);
tcp_output(tpcb);
pbuf_free(p);
return ERR_OK;
}
_______________________________________________
lwip-users mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/lwip-users