TCP Port numbers reused in telnet or MQTT connection

Hi,

I used the TelnetClient example to use Arduino telnet to a server at port 1883 and got connection failed. However, using my Mac to telnet to that server with the same port 1883 would always succeed.

The environment I got: - Arduino mega 2560 - Arduino Ethernet shield 2 - Ethernet shield 2 library - Arduino is connected to the Internet via router, and get a dynamical ip from DHCP server.

Eventually I plan to use Arduino connect to that server via MQTT. I reimplemented a java program on my Mac for verification. The java program can connect to that server while the Arduino just can't. And I tried to use Wireshark to monitor the MQTT traffic.

Filtering the packages collected from the java program with keywords "tcp.port eq 1883", I see several hand-shaking within the communication like below:

TCP 78  60836→1883 [SYN] Seq=0 Win=65535 Len=0 MSS=1460 WS=32 TSval=1209273071 TSecr=0 SACK_PERM=1
TCP 74  1883→60836 [SYN, ACK] Seq=0 Ack=1 Win=28160 Len=0 MSS=1420 SACK_PERM=1 TSval=714787051 TSecr=1209273071 WS=128
TCP 66  60836→1883 [ACK] Seq=1 Ack=1 Win=132352 Len=0 TSval=1209273127 TSecr=714787051
TCP 456 60836→1883 [PSH, ACK] Seq=1 Ack=1 Win=132352 Len=390 TSval=1209273132 TSecr=714787051

The .pcapng file is attached within this post.

While I got this from Arduino:

TCP 60  1025→1883 [SYN] Seq=0 Win=2048 Len=0 MSS=1460
TCP 70  1025→1883 [SYN] Seq=0 Win=2048 Len=0 MSS=1414
TCP 60  [TCP Port numbers reused] 1025→1883 [SYN] Seq=0 Win=2048 Len=0 MSS=1460
TCP 70  [TCP Port numbers reused] 1025→1883 [SYN] Seq=0 Win=2048 Len=0 MSS=1414
TCP 60  [TCP Retransmission] 1025→1883 [SYN] Seq=0 Win=2048 Len=0 MSS=1460
TCP 70  [TCP Retransmission] 1025→1883 [SYN] Seq=0 Win=2048 Len=0 MSS=1414
TCP 60  [TCP Retransmission] 1025→1883 [SYN] Seq=0 Win=2048 Len=0 MSS=1460
TCP 70  [TCP Retransmission] 1025→1883 [SYN] Seq=0 Win=2048 Len=0 MSS=1414

The TCP just got retransmission repeatedly.

I also catch the packages with the java program running on the Ethernet, not Wifi, and the results are just same. I noticed that the source port of java program running on Ethernet or Wifi is like 60836 or 62390 but is 1025 in Arduino. And the length of package is also different. But I don't know how to explain it.

I am not sure the message "TCP Port numbers reused" is due to the issue of Ethernet library/W5500 or the constrain of that server?

Thank you.