6 years, 9 months ago.  This question has been closed. Reason: Unclear question

socket not available for use, what does it mean??

Using two Nucleos F767 to communicate via Ethernet.

First Nucleo board sends UDP packages, second receives UDP packages.

Receiver

#include "mbed.h"
#include "EthernetInterface.h"
#include <string>

using std::string;

DigitalOut led1(LED1);
DigitalOut led2(LED2);

// Variables for setting network of Nucleo receiver
static const char *st_ip   = "169.254.5.32";  //IP
static const char *st_mask  = "255.255.255.0"; // Mask
static const char *st_gateway  = "";    //Gateway

//Network port to set-up socket address
const int PORT = 5081;

// ethernet network object on which will be build whole network with UDP socket
    EthernetInterface eth;

// create UDP socket
    UDPSocket socket(&eth);

void receive()
{
    SocketAddress rd;

    //bind to specific receiving port
    int bind = socket.bind(PORT);
    printf("bind return: %d\n", bind);

    //buffer for receved data
    char buffer[256];

    printf("\nWait for packet...\n");
    
    int ret = socket.recvfrom(&rd ,buffer, sizeof(buffer));
    if(ret > 0){
    buffer[ret] = '\0';
    printf("Packet from \"%s\": %s\n", rd.get_ip_address(), buffer);
    }
    else{
    printf("error %d\n", ret);
    printf("Packet from \"%s\": %s\n", rd.get_ip_address(), buffer);
    led2=!led2;
    }

}


int main() {

   
        eth.set_network(st_ip, st_mask, st_gateway); // set_network(const char *ip_address, const char *netmask, const char *gateway)
        eth.connect();
    // Show the network address
            const char *ip = eth.get_ip_address();
            printf("Controller IP address is: %s\n", ip ? ip : "No IP");
            printf("MAC address is: %s\n", eth.get_mac_address());

    while (true)
    {
        led1 = !led1;
        receive();
        wait_ms(5);
    }
}

Transmitter

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

#include <string>

using std::string;

DigitalOut led1(LED1);
DigitalOut led2(LED2);

// Variables for setting network for transmitter Nucleo in the box
static const char *st_ip1   = "169.254.5.22";  //IP
static const char *st_mask1  = "255.255.255.0";  // Mask
static const char *st_gateway1  = "";    //Gateway


static const char *st_ip = "169.254.5.32"; 

//Network port to set-up socket address
const int PORT = 5081;

// ethernet network object on which will be build whole network with UDP socket
    EthernetInterface eth;

// create UDP socket
    UDPSocket socket(&eth);

void transmit(){
        
        //Buffer for output messages
        const char* out_buffer = "very important data";

        //address of destination ip address and port
        SocketAddress td(st_ip, PORT);

        // Loop to send data to Socket address "td"
       
            int ret = socket.sendto(td, out_buffer, sizeof(out_buffer));
            printf("sendto return: %d\n", ret);      
}

int main(){
 
   
        eth.set_network(st_ip1, st_mask1, st_gateway1); // set_network(const char *ip_address, const char *netmask, const char *gateway)
        eth.connect();

    // Show the network address
            const char *ip = eth.get_ip_address();
            printf("Controller IP address is: %s\n", ip ? ip : "No IP");
            printf("MAC address is: %s\n", eth.get_mac_address());


    while (true)
    {
        led1 = !led1;

        transmit();
        
        wait_ms(1);
    }
}

Transmitter and receiver gives error -3005 : socket not available for use

Anybody have idea what could be wrong?

Daniel

Links to code in your compiler don't work for other people. You need to either post it here using <<code>> tags or commit and publish the code (the button next to compile) and then post a like to the project pages.

posted by Andy A 20 Jul 2017

fixed this

posted by Daniel Klioc 20 Jul 2017

On serial terminal getting this messsage : Controller IP Address is ïUoÝ®šÖFðwF`Äál¾ü}Ú*ý0§èV<N‚²_þ¿çûêÞV4KÄ„(ÿ» z].†½±f8Ö" bind return: -3005

posted by Daniel Klioc 21 Jul 2017