what is the difference between read() and recv() , and between send() and write() in socket programming ? performance and speed and other behavior.
views:
602answers:
4"Performance and speed"? Aren't those kind of ... synonyms, here?
Anyway, the recv()
call takes flags that read()
doesn't, which makes it more powerful, or at least more convenient. That is one difference. I don't think there is a significant performance difference, but haven't tested for it.
read() is equivalent to recv() with a flags parameter of 0. Other values for the flags parameter change the behaviour of recv(). Similarly, write() is equivalent to send() with flags == 0.
The only difference is that recv/send let you specify certain options for the actual operation . read/write are the 'universal' file descriptor functions while recv/send are slightly more specialized (for instance, you can set a flag to ignore SIGPIPE, or to send out-of-band messages...).
read()
and write()
are more generic, they work with any file descriptor.
However, they won't work on Windows.
You can pass additional options to send()
and recv()
, so you may have to used them in some cases.