I am trying to establish TCP communication between my PC and LWIP MCU. LWIP UDP and ICMP seems that work correctly. Note that LWIP works as TCP sender and PC-Python socket based script as receiver. The first cycle connection accept seems to be acknowledged correctly. However, during TCP packet sending it seems like the PC ACK are not correct - LWIP retransmits the packet.
LWIP code sender's side looks like this (obvious LWIP_Process function to handle received packets and refresh time, the initialization of MCU is not shown....)
static char first_pld[32] = {"Thank you people"};
/* -----------Set network id ----------*/
IP4_ADDR(&ipaddr, 192u, 168u, 100u, 2u);
IP4_ADDR(&ipaddr_pc, 192u, 168u, 100u, 10u);
/* -----------Force ARP discover routine ----------*/
LWIP_arp_query(&ipaddr_pc);
LWIP_Process();
/* -----------Start TCP communication ----------*/
MyTCP = tcp_new();
LWIP_Process();
tcp_bind(MyTCP, &ipaddr, 504);
LWIP_Process();
tcp_connect(MyTCP, &ipaddr_pc, 504, MyConnectedFn);
LWIP_Process();
tcp_sent(MyTCP, MySentFn);
LWIP_Process();
printf("TCP available to send: %04d\r\n", tcp_sndbuf(MyTCP));
LWIP_Process();
tcp_write(MyTCP, first_pld, strlen(first_pld), 0);
LWIP_Process();
tcp_output(MyTCP);
LWIP_Process();
while (1) {
LWIP_Process();
}
}
Python receiver is:
import socket
import sys
import time
buff_size = 128
# Create a TCP/IP socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# Bind the socket to the port
modbus_port = 504
this_addres = (b'192.168.100.10', modbus_port)
sock.bind(this_addres)
# Listen for incoming connections
sock.listen(1)
connection_status = 0
while connection_status == 0:
# Wait for a connection
print('waiting for a connection')
connection, client_address = sock.accept()
connection_status = 1
print("Connected to", client_address)
while 1:
payload = connection.recv(buff_size)
print(payload)
The wireshark log shows ARP session, accepting the TCP communication, but TCP packet send does not look correct - LWIP re-sends..
Wireshark Log Picture https://ibb.co/Q9fbxZ9
Any helpful tip please ? Currently I am trying to find similar solved trouble..