Cannot port forward to Spark outside Local Network

For libraries, you’ll see a little github icon next to the library (the little “octocat”). You see it in the screenshot you posted above. Click on that icon and it will take you to the sources. For the webserver, everything is in the header file.

@mdma

Yeah…all I saw was the prototypes in the header file. I was looking for the actual .cpp source.

I guess this is up to you sort out.

I am no expert, but I have found typically with sockets that you may need to block in a loop that checks for a socket to be closed before continuing. There is also a LINGER option available when you set the socket options so it waits gracefully for the socket to close before continuing. Hate to rely on delays, as I am sure you are aware of the pitfalls.

Thanks for your help! I hope you are able to sort this out…

If you scroll down to line 395, you’ll see the full source.

By all means take a look, an extra pair of eyes on the code is always welcome!

Regarding the webserver, the (client) socket is gracefully closed as soon as the response is sent. As this is an embedded implementation of berkley sockets, not all the socket or protocol options are supported - there is no SO_LINGER, so no control over any TIME_WAIT state. There may be some timeout happening after close, since subsequent connections take a long time to connect, as if they are waiting for the previous closed connection to exit it’s TIME_WAIT state, but this could equally be buffer starvation - and that’s something that needs to be investigated. There is also a setting applied at the network level for keep-alive, which is set to 10s (minimum value) which may play a role here.

I certainly understand the dangers with using delays as a workaround, especially since they are arbitrary, and would very much like to find a reasoned fix for this, as I’m sure would a lot of other folks here!