Noob networking setup with mbed-os-5.15

I’m using example code from and older version of mbed-os that sets up a network interface with a static IP as follows:

// Setup network interface
network = NetworkInterface::get_default_instance();
if (!network) {
pc.printf(“Cannot get default network instance\r\n”);
network->set_network(“”, “”, “”);

 // Connect network interface
 result = network->connect();

 if (result != NSAPI_ERROR_OK) {
     pc.printf("Error! network->connect() returned: %d\r\n", result);

The docs from OS 5.15 (and the warning from Mbed Studio) say that the string-based initialisation in set_network is deprecated & I should use SocketAddress objects instead. However in the SocketAddress docs I can’t find how to create/assign the netmask & default gateway. There appear to only be ip_address, network_stack and port_no methods.

Do I just create 3 SocketAddress objects named for example ‘ip’, mask’, ‘gw’ with respective ‘ip_address’ values corresponding to the ip address, netmask & gateway strings then call set_network(ip, mask, gw)?

Any advice appreciated.

Hello Chris,
I think you are right, you can either create three SocketAddress objects in advance and then call set_network or you can combine everything in one expression and create three temporary objects as arguments when calling set_network:

//network->set_network("", "", "");  // deprecated
network->set_network(SocketAddress(""), SocketAddress(""), SocketAddress(""));

Hi Zoltan,

Thanks, I’ll try your suggestion next week when I’m back in front of the dev system…

@hudakz - Thanks for your advice, that worked.

The last warnings I’m getting are in the ‘http_server.h’ header file from

which I’m using in my project for the webserver functionality I need.

It’s declaring a TCPServer (line 58 or so) that’s raising a deprecated warning, along with the associated TCPServer::accept() call in line 154.

The Mbed docs (and compiler warnings) say that TCPSocket should be used instead of TCPServer but I don’t have the understanding to adapt this code as it is already using other TCPSocket objects liberally.

I was able to get it to compile by re-declaring the ‘server’ object as TCPSocket and modifying the ::accept call, but the binary crashes on my target (EA LPC4088 QSB).