Is it possible to receive any empty payload with recvfrom()
with SOCK_DGRAM
based socket? The server is only interested in the client header to send it back a message (i.e. single message, send only protocol).
Asked
Active
Viewed 442 times
1

user7434748
- 41
- 3
-
Yes. You can send zero-length datagrams with UDP. – user207421 Feb 17 '17 at 11:23
-
@EJP How? `recvfrom()` never blocks on zero-lengths, and attempting to send empty package using for example `cat /dev/null | nc -u 127.0.0.1 1234` with `recvfrom()` in busy waiting does nothing. – user7434748 Feb 17 '17 at 22:04
-
With `send()`, or `sendto()`, supplying a zero length parameter. `recvfrom()` will block until a datagram is received or an error occurs. – user207421 Feb 18 '17 at 21:10
-
@EJP `recvfrom()` in my case never blocks and always returns zero. – user7434748 Feb 20 '17 at 09:39
1 Answers
0
0-sized datagrams are perfectly valid from socket API perspective and at least protocols IP, UDP, UNIX: one can send and receive them.

Maxim Egorushkin
- 131,725
- 17
- 180
- 271