views:

602

answers:

4

what is the difference between read() and recv() , and between send() and write() in socket programming ? performance and speed and other behavior.

+1  A: 

"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.

unwind
Perhaps not having to deal with flags may be perceived as more convenient.
semaj
+11  A: 

Per the first hit on Google

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.

Jonathan Feinberg
+5  A: 

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...).

Gonzalo
+1  A: 

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.

Bastien Léonard