I.e. after using a TCPServer instance to accept a new TCP connection, how can I retrieve the IP of the remote host? Looking at Socket, TCPServer and TCPSocket classes there doesn't seem to be an obvious mechanism for it.
cc @geky
This is a good question, and by good question, I mean this is a good question.
Most uses of the TCP server generally don't care where the incoming connection is from, so no one must have ran into this requirement yet. Thanks for raising the issue, as this functionality should be available.
Fortunately, this will be an easy API change to make, through overloading the TCPServer accept method:
/** Accepts a connection on a TCP socket
*
* The server socket must be bound and set to listen for connections.
* On a new connection, creates a network socket using the specified
* socket instance.
*
* By default, accept blocks until data is sent. If socket is set to
* non-blocking or times out, NSAPI_ERROR_WOULD_BLOCK is returned
* immediately.
*
* @param socket TCPSocket instance that will handle the incoming connection.
* @param Destination for the connection address or NULL
* @return 0 on success, negative error code on failure
*/
int accept(TCPSocket *connection, SocketAddress *address = NULL);
Let me know if you have any thoughts.
Cool :) That looks fine.
I've just come across the same issue while trying to migrate applications from mbed classic (using the separate EthernetInterface library) to mbed os 5.
Adding support would also surely require a change to the underlying nsapi layer (and therefore the several stack implementations), since the socket_accept method does not pass any address information.
@tommikas @infinnovation This should be resolved.
Most helpful comment
This is a good question, and by good question, I mean this is a good question.
Most uses of the TCP server generally don't care where the incoming connection is from, so no one must have ran into this requirement yet. Thanks for raising the issue, as this functionality should be available.
Fortunately, this will be an easy API change to make, through overloading the TCPServer accept method:
Let me know if you have any thoughts.