From 169b6448cf5388426699099c6a82b6046d9da816 Mon Sep 17 00:00:00 2001 From: Cifer Date: Thu, 21 Aug 2014 22:05:12 +0800 Subject: [PATCH] Some routers would block low number socket port When worked behind such a router, the tcp three-way handshake will fail due to the last ack message destined port 1024 blocked by router. So, when the board initiated a connection with a public server, using a bigger port number. --- libraries/Ethernet/EthernetClient.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/Ethernet/EthernetClient.cpp b/libraries/Ethernet/EthernetClient.cpp index ef3d19b8b41..0534a81ff31 100644 --- a/libraries/Ethernet/EthernetClient.cpp +++ b/libraries/Ethernet/EthernetClient.cpp @@ -12,7 +12,7 @@ extern "C" { #include "EthernetServer.h" #include "Dns.h" -uint16_t EthernetClient::_srcport = 1024; +uint16_t EthernetClient::_srcport = 31024; EthernetClient::EthernetClient() : _sock(MAX_SOCK_NUM) { } @@ -51,7 +51,7 @@ int EthernetClient::connect(IPAddress ip, uint16_t port) { return 0; _srcport++; - if (_srcport == 0) _srcport = 1024; + if (_srcport == 0) _srcport = 31024; socket(_sock, SnMR::TCP, _srcport, 0); if (!::connect(_sock, rawIPAddress(ip), port)) {