Problem with lwIp and lpc1769, tcp netconn api

Discussion created by lpcware Employee on Jun 15, 2016
Content originally posted in LPCWare by LucaCorradi on Sun Mar 09 13:41:07 MST 2014
Goodevening at all!

I've a problem with tcp client connection with netconn.

the code that I use is the same of the echo example. I've modified the code of echo function with:

static void
tcpecho_thread(void *arg)
struct netconn *conn;
err_t err;
ip_addr_t IpAdd;
ip_addr_t IpAddLoc;
struct netbuf* txBuffer;

  /* Create a new connection identifier. */
  conn = netconn_new(NETCONN_TCP);

  while (netif_list->ip_addr.addr == 0) {};
  IP4_ADDR(&IpAdd, 192, 168, 0, 1);
  IpAddLoc.addr = netif_list->ip_addr.addr;

  while (1) {
/* Tell connection to go into listening mode. */
err = netconn_connect(conn,&IpAdd,8080);

// check error for debug
if (err != ERR_OK) {
// Error

txBuffer = netbuf_new();
netbuf_alloc(txBuffer, 23); // 4 bytes of buffer
txBuffer->p->payload = "\fMaster Connected!!\n\n";
txBuffer->p->len = 23;

netconn_write(conn, txBuffer->p->payload, 23, NETCONN_COPY);

        vTaskDelay(100); // To see the result easily in Comm Operator


vTaskDelay(20000); //wait 20s

On the pc with address I've a tcp server that listen the port 8080. The first connection works ok, the message arrives and all it's ok, but the second time the connection doesn't happens and the error code is "-12" that is CloseConnection.

With WireShark the first time it's all ok, and the second time the lpc1769 doesn't send nothing.

The problem is generated from time-wait or similar problem? I've to mantain connection from server (remote) and client, if the connection fail for external problem, ADSL, cable , etc.. how I can reconnect if the second time lwip say that the connection is close?

I try also delete and recreate "conn struct" every cycle and works ok, but I think that is not a good method.