7 years, 5 months ago.

What does no suitable conversion function from "SocketAddress" to "SocketAddress" mean ?

Hi everyone ! I'm trying to make a UDP server and not knowing how to make one I decided to test it with an echo server, I found an example here: https://developer.mbed.org/teams/mbed/code/UDPEchoServer/ but the library wasn't compatible with my hardware (Nucleo-f429zi) so I tried it with the ethernetinterface in mbed-so.lib and it seems to be compatible, but every time I try to compile I get the same error with the recvfrom() function Error: No suitable conversion function from "SocketAddress" to "SocketAddress *" exists in "int n = server.recvfrom(client, buffer, sizeof(buffer));"

here is the code:

main.cpp

#include "mbed.h"
#include "EthernetInterface.h"
#include "Ethernet.h"

#include "SocketAddress.h"
#include "Socket.h"
#include "UDPSocket.h"


#define ECHO_SERVER_PORT   7

int main (void) {
    EthernetInterface eth;
    eth.connect();
    printf("\nServer IP Address is %s\n", eth.get_ip_address());
    
    UDPSocket server;
    server.bind(ECHO_SERVER_PORT);
    
    SocketAddress client;
    char buffer[256];
    while (true) {
        printf("\nWaiting for UDP packet...\n");
        int n = server.recvfrom(client, buffer, sizeof(buffer));
        buffer[n] = '\0';
        
        printf("Received packet from: %s\n", client.get_ip_address());
        printf("Packet contents : '%s'\n",buffer);
        printf("Sending Packet back to Client\n");
        server.sendto(client, buffer, n);
    }
}

1 Answer

7 years, 5 months ago.

Try passing in the address of the SocketAddress

int n = server.recvfrom(&client,buffer,sizeof(buffer));

Accepted Answer

The syntax is correct, dont need the & to get the base adress of the pointer... It compiles fine with an lpc4088...

You just only need as #include : "mbed.h" and "EthernetInterface.h"

remove all of others includes between lines #3 to #7. an try it to compil again.

If you need an ethernet interface use an lpc4088 qsb, it works very well.

posted by Raph Francois 01 Nov 2016