csocketsnetwork-programmingsend

What does "send data to" a socket mean in this part of Beej's guide?


Just getting into c network programming, and have been looking at Beej's guide. In the section on send() and recv() I came across this code:

int send(int sockfd, const void *msg, int len, int flags); 

followed by this sentence:

"sockfd is the socket descriptor you want to send data to (whether it’s the one returned by socket() or the one you got with accept())."

The way I understand it, if sockfd is a stream socket, it's in a connected state. By "sockfd is the socket descriptor you want to send data to", does this mean the data is actually sent (by way of sockfd) to the recv() 'ing socket connected to sockfd?


Solution

  • Yes, send() (or write(), writev() etc) can be used to copy data to a peer via the open socket. The peer can then use recv() (or read(), readv() etc) to obtain the data.