【发布时间】:2019-09-10 16:37:12
【问题描述】:
我正在尝试在我的 PC 和 LWIP MCU 之间建立 TCP 通信。 LWIP UDP 和 ICMP 似乎工作正常。请注意,LWIP 用作 TCP 发送器,而基于 PC-Python 套接字的脚本用作接收器。第一个循环连接接受似乎已正确确认。但是,在发送 TCP 数据包期间,PC ACK 似乎不正确 - LWIP 重新传输数据包。
LWIP代码发送端是这样的(明显LWIP_Process函数处理接收到的数据包和刷新时间,MCU的初始化不是 显示...)
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 接收器是:
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)
wireshark 日志显示 ARP 会话,接受 TCP 通信,但是 TCP 数据包发送看起来不正确 - LWIP 重新发送..
Wireshark 日志图片https://ibb.co/Q9fbxZ9
请问有什么有用的提示吗?目前我正在尝试找到类似的已解决问题..
【问题讨论】: