各位大神,LWIP TCP客户端长连接,服务器端一旦将TCP关闭,就会导致系统重启,不知到什么原因,请各位大神支招。谢谢! 下面是连接与接收数据源码。
void tcpcheckfun(void *arg, err_t err)
{
if(0 == err)
opencpu_printf ( "tcp OK\n");
else
{
opencpu_printf ( "tcp err\n");
}
}
static err_t deal_rec(void *arg, struct tcp_pcb *pcb,struct pbuf *p,err_t err)
{
char * data = NULL;
char *UserName =NULL;
char *PassWord =NULL;
char *LED_CMD =NULL;
char *ch =NULL;
data = p->payload;
if (err == ERR_OK && p != NULL)
{
opencpu_printf(data);
opencpu_printf("Rec from server\r\n");
pbuf_free(p);
}
//tcp_close(pcb);
//tcp_err(Clipcb,&tcpcheckfun);
err = ERR_OK;
return err;
}
err_t TcpCli_Connected(void *arg, struct tcp_pcb *tpcb, err_t err)
{
//tcp_arg(pcb, mem_calloc(sizeof(struct name), 1));
tcp_err(tpcb,tcpcheckfun);
opencpu_printf ( "tcp send......\n");
tcp_write(tpcb,test_msg,sizeof(test_msg),0);
tcp_setprio(tpcb, TCP_PRIO_MIN);
opencpu_printf ( "tcp rec......\n");
tcp_recv(tpcb,deal_rec);
return ERR_OK;
}
#define server_point 1100
void tcp_test()
{
struct tcp_pcb *Clipcb;
ip_addr_t ipaddr1;
IP4_ADDR(&ipaddr1,192,168,0,1); //
Clipcb = tcp_new(); ;//
ip_set_option(Clipcb, SOF_KEEPALIVE|SOF_REUSEADDR);
tcp_bind(Clipcb,IP_ADDR_ANY,server_point);//&ipaddr1IP_ADDR_ANY,point); //
opencpu_printf ( "tcp connecting......\n");
tcp_connect(Clipcb,&ipaddr1,server_point,TcpCli_Connected); // |