Difference between recv and read, send and write

Asked

Viewed 726 times

1

I am transmitting and collecting data from a connection using Sockets, to send the data to the server, you can use the commands send and write, and to receive the data recv and read.

  • There is a difference in these commands?

  • What advantage/disadvantage you may have in using send or write to send some data?

  • What advantage/disadvantage you may have in using recv or read to receive some data?

1 answer

1


Send

Both clients and servers use the function send to transmit data. Typically, a client sends a request and the server sends a response.

Recv

Both clients and servers use the function recv to obtain data sent by the other.

Read and Write

On some operating systems, such as Linux, the functions read and write may be used instead of recv and send.

Read and Write Advantage The great advantage of using read and write is the generalization - an application can be created for the purpose of transferring data to or from a descriptor without knowing if it corresponds to a file or a socket. This way, a programmer can use a file on the local disk to test a client or a server before trying to communicate over the network.

Disadvantage of Read and Write The program loses portability when it is compiled into another operating system.

Source 01 : Computer network and Internet - 6 ed. Douglas E. Comer Source 02 : https://stackoverflow.com/a/1790775/2588695

  • 2

    Still the use of read/write instead of send/recv implies not using the flags allowed by the send and recv functions (it is equivalent to passing 0 instead of this parameter in the functions that have it).

  • I forgot to put this part srsrsrsrs

Browser other questions tagged

You are not signed in. Login or sign up in order to post.