Hi. My code is raw tcp/ip client application. It can connect local server on my computer frequently but it can't connect to remote server "sometimes (about 2/3 ratio) " . Remote server is working properly, I guarantee by connecting my computer with simple socket application. If I try to execute TCP_WRITE function, return error 13 so connection error.
I think that My device can't get ACK in timeout or I don't know.
How can ı solve this ?
My device is LPC1769. I use changed LPCopen TCP/IP Server App to client version by myself.
I add some code block related with changed from lpcopen example.
I attach my lwipopt.h, that options can execute webserver application with 70kb webpage very fast.
My pcb is blocked at echo_pcb->state = SYN_Sent. It can't get ACK
void tcp_echoclient_connect(void) { struct ip_addr DestIPaddr; if (echo_pcb != NULL) { IP4_ADDR( &DestIPaddr, 192, 168, 1, 39 ); /* connect to destination address/port */ tcp_connect(echo_pcb,&DestIPaddr,7,echo_accept); } else { /* deallocate the pcb */ memp_free(MEMP_TCP_PCB, echo_pcb); // DEBUGOUT("\n\r can not create tcp pcb"); } } void echo_init(void) { echo_pcb = tcp_new(); if (echo_pcb != NULL) { err_t err; err = tcp_bind(echo_pcb, IP_ADDR_ANY,7); if (err == ERR_OK) { tcp_echoclient_connect(); } else { /* abort? output diagnostic? */ } } else { /* abort? output diagnostic? */ } } int Enet_Write(char *str){ err_t wr_err = ERR_OK; while ( (str != NULL) && (strlen(str) <= tcp_sndbuf(echo_pcb)) && strlen(str) < 1025 && echo_pcb != NULL) { wr_err = tcp_write(echo_pcb, str, strlen(str) , 1); if (wr_err == ERR_OK) { tcp_output(echo_pcb); DEBUGOUT("Transmitted data is : %s\r\n", str); if( echo_pcb->unacked != NULL ) DEBUGOUT("Acknowledged \r\n"); break; } else if(wr_err == ERR_MEM) { /* we are low on memory, try later / harder, defer to poll */ DEBUGOUT("Tcp_write memory error \r\n"); } else { /* other problem ?? */ DEBUGOUT("wr_err is %d \r\n",wr_err); } } }
Flamador, sorry for the late reply here. I am looking for someone who might be able to help here! Please hang tight :)
No problem, So thanks :)