2nd TCPClient connection fails

I am trying to connect to a FTP server using a passive connection. It worked fine in 0.6.4, but now fails in 0.7.0.

The issue appears when trying to set up the second (data) connection to the FTP server. The Particle firmware doesn’t even send out a packet, it just returns immediately without connecting.

Using the code below with 0.7.0 the second connection fails - we have servers running on port 21 and 65001 so both connections should work.

  TCPClient conn1;
  TCPClient conn2;

  conn1.connect(ahostname, 21);

  if (conn1.connected())
    CSTR_LOG(LOG_ERROR, "Conn1 Connected")
  else
    CSTR_LOG(LOG_ERROR, "Conn1 not Connected");

  conn2.connect(ahostname, 65001);

  if (conn2.connected())  // <--- connection fails
    CSTR_LOG(LOG_ERROR, "Conn2 Connected")
  else
    CSTR_LOG(LOG_ERROR, "Conn2 not Connected");

Stopping the first conn1 before opening conn2 allows conn2 to connect.

  TCPClient conn1;
  TCPClient conn2;

  conn1.connect(ahostname, 21);

  if (conn1.connected())
    CSTR_LOG(LOG_ERROR, "Conn1 Connected")
  else
    CSTR_LOG(LOG_ERROR, "Conn1 not Connected");

  conn1.stop();  // <-- Add this line and conn2 connects

  conn2.connect(ahostname, 65001);

  if (conn2.connected())
    CSTR_LOG(LOG_ERROR, "Conn2 Connected")
  else
    CSTR_LOG(LOG_ERROR, "Conn2 not Connected");

I haven’t found a workaround and we really need the FTP functionality ASAP. If you find a solution I would very much appreciate you posting it here.

Is this on a Photon/P1 (Wi-Fi) or Electron (Cellular)? I’ll try to reproduce this.

1 Like

Hi,

It’s on an Electron. I’ve just tried downgrading to 6.4.0 and it still fails.

Cheers,
Paul

I tried my FTP client test on 0.7.0 and it worked fine. It opened the command connection to port 21 and it logged in, then opened the data connection successfully and transferred data.

You might want to try getting a debug log and see what’s actually failing. I have this at the top of my source file:

SerialDebugOutput debugOutput(9600, ALL_LEVEL);
1 Like

Seems like an update we made elsewhere in the code is affecting the TCPClient in the ftp class. It’s a very strange issue. I’m working back through the changes to try to isolate the problem.

Thanks for the SerialDebugOutput tip. I wish I’d known about it earlier :slight_smile:

1 Like

@rikkas7 - Are you aware of any limitations when it comes to active TCP/UDP clients on the Electron?

I fixed it.

It appears that the Particle OS - or modem - has a hard client socket limit of 7. If you try to open an 8th socket it just fails and returns 0. Here are the logs for the 7th (working) attempt.

socketSocket(TCP)
   143.579 AT send      12 "AT+USOCR=6\r\n"
   143.591 AT read  +   13 "\r\n+USOCR: 6\r\n"
   143.603 AT read OK    6 "\r\nOK\r\n"
Socket 6: handle 6 was created

… and the 8th (failed) effort

socketSocket(TCP)

Would be nice if there was an error in the log when the socket connection fails in this way.

Thanks for your help :slight_smile:

1 Like