Hello All,
I want to send 792 byte data from my client gateway to the server over ethernet. Now I am able to send all data over ethernet but everytime I open new connection. you can see the conenction inside yellow circle. But I want to send all data over ethernet without opening new connection. I mean ı want only one connection in the yellow circle.
you can see the code below.
How can I configure this code to do for one connection? please let me know if you have an idea.
void ETH_Connection_Proccess(void) { if(Gateway.ETHERNET_Mode == 0) { usb_printf("\n",1); usb_printf("ETH NOT ENABLED CAN'T POST MESSAGE\n", 35); Gateway.Priority = Gateway.ETHERNET_Priority + 1; } else if(ETH_Ctrl.eth_connection_status == 0) { usb_printf("\n",1); usb_printf("ETH NOT CONNECTED CAN'T POST MESSAGE\n", 37); Gateway.Priority = Gateway.ETHERNET_Priority + 1; } else if(ETH_Ctrl.eth_connection_status == 1 && Gateway.ETHERNET_Mode == 1) { ETH_Ctrl.connectTYPE = ETHERNET_POST; // // Connect to host address // tcp_echoclient_connect(Gateway.Host_Address,Gateway.Remote_Port_Number); ETH_Ctrl.status = ETH_POST_CONNECT_SENT; ETH_Ctrl.timeout = 1; } }
/** * @brief Connects to the TCP echo server * @param None * @retval None */ void tcp_echoclient_connect(char* IP_ARR,char* PORT_NUM) { ip_addr_t DestIPaddr; uint16_t DestPORTAddr; /* create new tcp pcb */ echoclient_pcb = tcp_new(); if (echoclient_pcb != NULL) { ipaddr_aton((const char *)IP_ARR,&DestIPaddr); DestPORTAddr = atoi(PORT_NUM); /* connect to destination address/port */ tcp_connect(echoclient_pcb,&DestIPaddr,DestPORTAddr,tcp_echoclient_connected); } } /** * @brief Function called when TCP connection established * @param tpcb: pointer on the connection contol block * @param err: when connection correctly established err should be ERR_OK * @retval err_t: returned error */ static err_t tcp_echoclient_connected(void *arg, struct tcp_pcb *tpcb, err_t err) { struct echoclient *es = NULL; // uint16_t index2; uint16_t data_lenght; data_lenght=792; if (err == ERR_OK) { /* allocate structure es to maintain tcp connection informations */ es = (struct echoclient *)mem_malloc(sizeof(struct echoclient)); if (es != NULL) { es->state = ES_CONNECTED; es->pcb = tpcb; if(ETH_Ctrl.connectTYPE == ETHERNET_POST) { // sprintf((char*)data,"%sContent-Length: %d\r\n\r\n%s\r\n",Gateway.POST_message_constant_part,Gateway.tcp_message_length,Gateway.tcp_message); memcpy(data,Gateway.tcp_message,Gateway.tcp_message_length); //1024 tcp message datanın ilk 792 adet datası databuffer içine kaydedilir /* allocate pbuf */ es->p_tx = pbuf_alloc(PBUF_TRANSPORT, sizeof(data) , PBUF_POOL); //burası gönderilen buffer ile aynı ozellikte bos bir buffer yaratıyor if (es->p_tx) { /* copy data to pbuf */ // pbuf_take(es->p_tx, (char*)data, strlen((char*)data)); pbuf_take(es->p_tx, (char*)data, data_lenght); //792 byte burada yukarıda yeni tanımlananan buffera, data bufferını kopyalıyoruz /* pass newly allocated es structure as argument to tpcb */ tcp_arg(tpcb, es); /* initialize LwIP tcp_recv callback function */ tcp_recv(tpcb, tcp_echoclient_recv); /* initialize LwIP tcp_sent callback function */ tcp_sent(tpcb, tcp_echoclient_sent); /* initialize LwIP tcp_poll callback function */ tcp_poll(tpcb, tcp_echoclient_poll, 1); /* send data */ tcp_echoclient_send(tpcb,es); return ERR_OK; } } } else { /* close connection */ tcp_echoclient_connection_close(tpcb, es); /* return memory allocation error */ return ERR_MEM; } } else { /* close connection */ tcp_echoclient_connection_close(tpcb, es); } return err; }
thank you
BR,
Bekir