Hello,
I am using the following line in my code: r = send(socket, data, strlen(data), 0);
r is -1 and the errno is: 22.
is there a list of errornumbers with their explanation?
Thank you and regards,
Wamor
send(socket, data, strlen(data), 0) returned errors
Re: send(socket, data, strlen(data), 0) returned errors
Wamor,
See the following manual page on send():
http://man7.org/linux/man-pages/man2/send.2.html
At the end, you will see the possible symbolic definitions of error codes that can be found in the errno global. See also the function called "strerror()" that takes the value of errno as input and returns a string representation.
Most folks try and "shy away" from thinking of errno in terms of numeric values as they can legally vary from platform to platform and over time even on the same platform. If you want to see what the meaning of a specific value is at any given time on the ESP32, look in the the following file:
https://github.com/espressif/esp-idf/bl ... ys/errno.h
See the following manual page on send():
http://man7.org/linux/man-pages/man2/send.2.html
At the end, you will see the possible symbolic definitions of error codes that can be found in the errno global. See also the function called "strerror()" that takes the value of errno as input and returns a string representation.
Most folks try and "shy away" from thinking of errno in terms of numeric values as they can legally vary from platform to platform and over time even on the same platform. If you want to see what the meaning of a specific value is at any given time on the ESP32, look in the the following file:
https://github.com/espressif/esp-idf/bl ... ys/errno.h
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32
Re: send(socket, data, strlen(data), 0) returned errors
Hello kolban,
Thank you for you explanation.
I use the following code:
My socketnumber is obtanined like this and seems to be 0:
Could this be the source of my error because the last 3 parameters could not be wrong?
Can socketnumber be 0?
Regards,
Wamor
Thank you for you explanation.
I use the following code:
Code: Select all
char *data = "Hello world";
r = send(socketnumber, data, strlen(data), 0);
ESP_LOGI(TAG, "... done sending to socket. Last read return=%d errno=%d", r, errno);
Code: Select all
socketnumber = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
Can socketnumber be 0?
Regards,
Wamor
Re: send(socket, data, strlen(data), 0) returned errors
Howdy Wamor,
A socket number of 0 is fine ... it is merely an integer handle that represents a channel for communication and the first one you create can be 0. If socket() returned -1 then there would have been an issue. Based on the information you presented, my first guess is that you might have a mis-understanding on datagrams and sockets(). The ESP32 implements a pretty clean distribution of the sockets() API and a solid study of sockets programming outside the scope of the ESP32 would do no harm. In fact, for many tasks, actually developing your sockets logic on a PC (eg. Linux) would do no harm and the port to ESP32 should be trivial.
What I think I am seeing is that sockets() is an API on TCP/IP and TCP/IP has two distinct higher level protocols. These are TCP for connection oriented data transmission and UDP for data grams (fire and forget). The socket you created is a datagram socket. What that means is that it isn't "connected" to a partner. As such, when you wish to send a datagram, you need to instruct the environment where you wish to send it. This can be accomplished by using the sockets API called "sendto()" ... see:
https://linux.die.net/man/2/sendto
which takes a destination address (IP and port) as additional parameters as compared to send().
Now this isn't the only way to send data grams, I believe one can bind an address to a data gram socket ... but without seeing more of the logic/design, I can't say for sure what the issue may be ... but the above might be a sensible guess.
A socket number of 0 is fine ... it is merely an integer handle that represents a channel for communication and the first one you create can be 0. If socket() returned -1 then there would have been an issue. Based on the information you presented, my first guess is that you might have a mis-understanding on datagrams and sockets(). The ESP32 implements a pretty clean distribution of the sockets() API and a solid study of sockets programming outside the scope of the ESP32 would do no harm. In fact, for many tasks, actually developing your sockets logic on a PC (eg. Linux) would do no harm and the port to ESP32 should be trivial.
What I think I am seeing is that sockets() is an API on TCP/IP and TCP/IP has two distinct higher level protocols. These are TCP for connection oriented data transmission and UDP for data grams (fire and forget). The socket you created is a datagram socket. What that means is that it isn't "connected" to a partner. As such, when you wish to send a datagram, you need to instruct the environment where you wish to send it. This can be accomplished by using the sockets API called "sendto()" ... see:
https://linux.die.net/man/2/sendto
which takes a destination address (IP and port) as additional parameters as compared to send().
Now this isn't the only way to send data grams, I believe one can bind an address to a data gram socket ... but without seeing more of the logic/design, I can't say for sure what the issue may be ... but the above might be a sensible guess.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32
Who is online
Users browsing this forum: No registered users and 93 guests