LWIP Can't Connect to Remote Server

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

LWIP Can't Connect to Remote Server

3,812 Views
ramazan_kurban3
Contributor III

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.

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);
}
}

}

Labels (1)
0 Kudos
5 Replies

3,516 Views
FelipeGarcia
NXP Employee
NXP Employee

Hi Ramazan,

 

It would be useful if you could debug what type of error are you seeing. If you check tcp_connect API you will see there are different types of error. Please check the definitions below from err.h.

/* Definitions for error constants. */

#define ERR_OK          0    /* No error, everything OK. */
#define ERR_MEM        -1    /* Out of memory error.     */
#define ERR_BUF        -2    /* Buffer error.            */
#define ERR_TIMEOUT    -3    /* Timeout.                 */
#define ERR_RTE        -4    /* Routing problem.         */
#define ERR_INPROGRESS -5    /* Operation in progress    */
#define ERR_VAL        -6    /* Illegal value.           */
#define ERR_WOULDBLOCK -7    /* Operation would block.   */
#define ERR_USE        -8    /* Address in use.          */
#define ERR_ISCONN     -9    /* Already connected.       */

#define ERR_IS_FATAL(e) ((e) < ERR_ISCONN)

#define ERR_ABRT       -10   /* Connection aborted.      */
#define ERR_RST        -11   /* Connection reset.        */
#define ERR_CLSD       -12   /* Connection closed.       */
#define ERR_CONN       -13   /* Not connected.           */

#define ERR_ARG        -14   /* Illegal argument.        */

#define ERR_IF         -15   /* Low-level netif error    */

Best regards,

Felipe

0 Kudos

3,516 Views
ramazan_kurban3
Contributor III

My pcb is blocked at echo_pcb->state = SYN_Sent. It can't get ACK

0 Kudos

3,516 Views
FelipeGarcia
NXP Employee
NXP Employee

The link-up for connection means hardware PHY's connection. Normally, this error means invalid connections.

 

Regards,

Felipe

0 Kudos

3,516 Views
ramazan_kurban3
Contributor III

My device can connect to my local server properly, My pc can connect to my remote server properly but my device can't connect to remote server sometimes. It can run web server properly with this hardware setup so ı think hardware is true.

0 Kudos

3,516 Views
ramazan_kurban3
Contributor III

It gives -13 error. 

0 Kudos