|
本帖最后由 kael_wyh 于 2020-8-9 02:30 編輯
1、如果開始的時候服務(wù)器是開啟狀態(tài),那么所有狀態(tài)都正常
2、如果服務(wù)器關(guān)閉后,lwip連接斷開,然后服務(wù)器開啟,lwip重新創(chuàng)建tcp,會出現(xiàn)連接無反應(yīng),狀態(tài)一直是23、這情況也會出現(xiàn)在從一開始服務(wù)器就關(guān)閉,然后等重連幾次后開啟服務(wù)器,也會出現(xiàn)連接無反應(yīng)
4、代碼都走到了重連地方
代碼:
- cpcb = pCon->cpcb;
- if( isErrorState(cpcb->state) || pCon->lastSendStatus==0 )//
- {
- pCon->isConnected = 0;
-
- if( time - pCon->connectTime > 10000 ) //等10秒
- {
- pCon->connectTime = time;
- pCon->lastSendTime = time;
- pCon->lastSendStatus = 1;
-
- tcp_close(cpcb);
-
- if( isDebug ) printf( "reconnected: %d, %d\r\n", cpcb->state, getActivePcbCount() );
-
- pCon->cpcb = TCP_Client_Init( pCon, getLocalPort(), 0, pCon->ips[0], pCon->ips[1], pCon->ips[2], pCon->ips[3] );
- }
- }
復(fù)制代碼- struct tcp_pcb * TCP_Client_Init( Con *pCon, u16_t local_port, u32 remove_ip, unsigned char a,unsigned char b,unsigned char c,unsigned char d)
- {
- u8 t;
- struct ip_addr ipaddr;
- struct tcp_pcb *tcp_client_pcb;
-
- err_t err;
-
- if( remove_ip==0 )
- IP4_ADDR(&ipaddr,a,b,c,d); //服務(wù)器IP地址
- else ipaddr.addr = remove_ip;
-
- tcp_client_pcb = tcp_new(); /* 建立通信的TCP控制塊(Clipcb) */
- if (!tcp_client_pcb)
- {
- trace( "tcp new null\r\n" );
- return NULL;
- }
- pCon->cpcb = tcp_client_pcb;
-
- tcp_client_pcb->flags |= (TF_NODELAY);
- tcp_client_pcb->so_options |= SOF_KEEPALIVE;
- tcp_client_pcb->nrtx = 0;
-
- err = tcp_bind(tcp_client_pcb,IP_ADDR_ANY,local_port); /* 綁定本地IP地址和端口號 ,本地ip地址在LwIP_Init()中已經(jīng)初始化*/
- if(err != ERR_OK)
- {
- tcp_close(tcp_client_pcb);
- trace( "tcp bind error\r\n" );
- return NULL;
- }
- if( ERR_OK != (t = tcp_connect(tcp_client_pcb,&ipaddr,pCon->port,TCP_Connected)) )
- {
- if( isDebug ) printf( "connect error: %d\r\n", t );
- }
-
- tcp_recv(tcp_client_pcb,TCP_Client_Recv); /* 設(shè)置tcp接收回調(diào)函數(shù) */
- tcp_err( tcp_client_pcb, tcp_error_callback );
-
- return tcp_client_pcb;
- }
復(fù)制代碼
|
|